<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sleepiness in Seattle &#187; javascript</title>
	<atom:link href="http://stanblog.jojoyao.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://stanblog.jojoyao.com</link>
	<description>Stanley&#039;s Chat on the Technology and Business</description>
	<lastBuildDate>Tue, 21 Apr 2009 04:29:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Cross-browser Event Handler Assignment</title>
		<link>http://stanblog.jojoyao.com/2007/06/cross-browser-event-handler-assignment/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cross-browser-event-handler-assignment</link>
		<comments>http://stanblog.jojoyao.com/2007/06/cross-browser-event-handler-assignment/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 15:17:33 +0000</pubDate>
		<dc:creator>Stanley Yao</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://stanblog.jojoyao.com/newblog/?p=44</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<div id="dvAmpBorderBottom" style="DISPLAY: none; FONT-SIZE: 3px; Z-INDEX: 999999; WIDTH: 200px; LINE-HEIGHT: 4px; POSITION: absolute; HEIGHT: 4px; BACKGROUND-COLOR: #ff9900"></div>
<div id="dvAmpBorderTop" style="DISPLAY: none; FONT-SIZE: 3px; Z-INDEX: 999999; WIDTH: 200px; LINE-HEIGHT: 4px; POSITION: absolute; HEIGHT: 4px; BACKGROUND-COLOR: #ff9900"></div>
<div id="dvAmpBorderRight" style="DISPLAY: none; FONT-SIZE: 3px; Z-INDEX: 999999; WIDTH: 4px; LINE-HEIGHT: 4px; POSITION: absolute; HEIGHT: 200px; BACKGROUND-COLOR: #ff9900"></div>
<div id="dvAmpBorderLeft" style="DISPLAY: none; FONT-SIZE: 3px; Z-INDEX: 999999; WIDTH: 4px; LINE-HEIGHT: 4px; POSITION: absolute; HEIGHT: 200px; BACKGROUND-COLOR: #ff9900"></div>
<p>Making the client side scripts work across different major browsers is not easy, especially when client debugging is not as convenient as more strongly typed programming languages.&nbsp; Try the following web page.&nbsp; It works fine on IE but on FireFox clicking the button will trigger nothing to happen.</p>
<table cellspacing="1" cellpadding="1" width="95%" align="center" summary="" border="1">
<tbody>
<tr>
<td><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">html</font><font size="2"> </font><font color="#ff0000" size="2">xmlns</font><font color="#0000ff" size="2">=&quot;http://www.w3.org/1999/xhtml&quot;</font><font size="2"> </font><font color="#0000ff" size="2">&gt;<br />
&lt;</font><font color="#a31515" size="2">head</font><font color="#0000ff" size="2">&gt;</font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">title</font><font color="#0000ff" size="2">&gt;</font><font size="2">Untitled Page</font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">title</font><font color="#0000ff" size="2">&gt;&lt;/</font><font color="#a31515" size="2">head</font><font color="#0000ff" size="2">&gt;<br />
&lt;</font><font color="#a31515" size="2">script</font><font size="2"> </font><font color="#ff0000" size="2">language</font><font color="#0000ff" size="2">=&quot;Javascript&quot;&gt;<br />
function</font><font size="2"> document.onclick() {<br />
&nbsp; alert(</font><font color="#a31515" size="2">&#8216;doc event&#8217;</font><font size="2">);<br />
}<br />
</font><font color="#0000ff" size="2">function</font><font size="2"> foo() {<br />
&nbsp; alert(</font><font color="#a31515" size="2">&#8216;foo&#8217;</font><font size="2">);<br />
}<br />
</font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">script</font><font color="#0000ff" size="2">&gt;<br />
&lt;</font><font color="#a31515" size="2">body</font><font color="#0000ff" size="2">&gt;<br />
&lt;</font><font color="#a31515" size="2">input</font><font size="2"> </font><font color="#ff0000" size="2">type</font><font color="#0000ff" size="2">=&quot;button&quot;</font><font size="2"> </font><font color="#ff0000" size="2">value</font><font color="#0000ff" size="2">=&quot;ok&quot;</font><font size="2"> </font><font color="#ff0000" size="2">onclick</font><font color="#0000ff" size="2">=&quot;foo();&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;<br />
&lt;/</font><font color="#a31515" size="2">body</font><font color="#0000ff" size="2">&gt;<br />
&lt;/</font><font color="#a31515" size="2">html</font><font color="#0000ff" size="2">&gt;</font></td>
</tr>
</tbody>
</table>
<p>The page will silently fail and none of the event handlers works.&nbsp; Change the document.onclick handler assignment into the following and it works on both browsers.&nbsp; Tools like the Error Console on FireFox is very helpful in diagnosing these type of errors.</p>
<table cellspacing="1" cellpadding="1" width="95%" align="center" summary="" border="1">
<tbody>
<tr>
<td><font color="#0000ff" size="2">&#8230;<br />
</font><font size="2">document.onclick = function () {<br />
&nbsp; alert(</font><font color="#a31515" size="2">&#8216;doc event&#8217;</font><font size="2">);<br />
}<br />
&#8230;</font></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://stanblog.jojoyao.com/2007/06/cross-browser-event-handler-assignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>innerHTML could invalidate the event handlers of its child elements</title>
		<link>http://stanblog.jojoyao.com/2007/05/innerhtml-could-invalidate-the-event-handlers-of-its-child-elements/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=innerhtml-could-invalidate-the-event-handlers-of-its-child-elements</link>
		<comments>http://stanblog.jojoyao.com/2007/05/innerhtml-could-invalidate-the-event-handlers-of-its-child-elements/#comments</comments>
		<pubDate>Fri, 11 May 2007 04:48:10 +0000</pubDate>
		<dc:creator>Stanley Yao</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://stanblog.jojoyao.com/newblog/?p=40</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p>In Javascript, using an element&#8217;s innerHTML property to dynamically edit its content provides much flexibility and convenience.&nbsp; But special care needs to be taken when using it, because it could bite you silently.&nbsp; Take one of my experiences as an example, it could break the event handlers of the child elements.&nbsp; Sample code as the following:</p>
<table width="90%" cellspacing="1" cellpadding="1" border="1" align="center" summary="">
<tbody>
<tr>
<td>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;innerHTML&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;hr /&gt;&lt;div id=&quot;myd&quot;&gt;&lt;/div&gt;&lt;hr /&gt;</p>
<p>&lt;script language=&quot;javascript&quot;&gt;<br />
function myaction()<br />
{<br />
&nbsp;&nbsp;&nbsp; alert(&quot;hello&quot;);<br />
}</p>
<p>var d1 = document.createElement(&quot;div&quot;);<br />
d1.onclick = myaction;<br />
d1.innerHTML = &quot;child div&quot;;</p>
<p>var d = document.getElementById(&quot;myd&quot;);<br />
d.appendChild(d1);<br />
//d.innerHTML += &quot;parent div&quot;;<br />
&lt;/script&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<p>
This code works well and when you click on div, &quot;hello&quot; will pop up.&nbsp; However if you uncomment the last line of the JavaScript code.&nbsp; The message won&#8217;t pop up any more.&nbsp; innerHTML manipulates the content of the element as a string instead of DOM, so it might just break the underlying &quot;wires&quot; that hooks up the elements and their event handlers.&nbsp; So watch out, when any of the events stops working as expected, look for the evil &quot;innerHTML&quot; first.</p>
]]></content:encoded>
			<wfw:commentRss>http://stanblog.jojoyao.com/2007/05/innerhtml-could-invalidate-the-event-handlers-of-its-child-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysterious JavaScript function call failure and loading optimization</title>
		<link>http://stanblog.jojoyao.com/2007/01/mysterious-javascript-function-call-failure-and-loading-optimization/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysterious-javascript-function-call-failure-and-loading-optimization</link>
		<comments>http://stanblog.jojoyao.com/2007/01/mysterious-javascript-function-call-failure-and-loading-optimization/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 18:57:40 +0000</pubDate>
		<dc:creator>Stanley Yao</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[defer]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://stanblog.jojoyao.com/newblog/?p=8</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a title="Optimize Your Scripts in DHTML Using the DEFER Attribute" href="http://www.devx.com/tips/Tip/13082">Optimize Your Scripts in DHTML Using the DEFER Attribute</a> </p>
<p>When, for example, a perfect JavaScript function call foo() with the correct syntax is always mysteriously ignored, watch out for the side effect of script loading optimization.  The root cause turned out to be that the script that contains the foo() function is loaded like the the following with &quot;defer&quot;:</p>
<table width="90%" cellspacing="1" cellpadding="1" border="1" bgcolor="#ddddff" align="center" summary="">
<tbody>
<tr>
<td>&lt;script src=&quot;foo.js&quot; type=&quot;text/javascript&quot; defer&gt; &lt;/script&gt;</td>
</tr>
</tbody>
</table>
<p></p>
<table width="90%" cellspacing="1" cellpadding="1" border="1" bgcolor="#ddddff" align="center" summary="">
<tbody>
<tr>
<td>//foo.js<br />
function foo() {<br />
&nbsp;&nbsp;&nbsp; document.write(&quot;hello&quot;);<br />
}</td>
</tr>
</tbody>
</table>
<p>
Optimization never comes for free.  Watch out for the side effects it may brings.</p>
]]></content:encoded>
			<wfw:commentRss>http://stanblog.jojoyao.com/2007/01/mysterious-javascript-function-call-failure-and-loading-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

