<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Programming collection</title>
	<atom:link href="http://terenceyim.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://terenceyim.wordpress.com</link>
	<description>Programming collection</description>
	<lastBuildDate>Wed, 02 Sep 2009 17:31:28 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='terenceyim.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/02e148cee44f92fa9d47a9491329b616?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Programming collection</title>
		<link>http://terenceyim.wordpress.com</link>
	</image>
			<item>
		<title>I am lucky to get the new layout</title>
		<link>http://terenceyim.wordpress.com/2009/08/13/i-am-lucky-to-get-the-new-layout/</link>
		<comments>http://terenceyim.wordpress.com/2009/08/13/i-am-lucky-to-get-the-new-layout/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 04:45:55 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[Tech news]]></category>
		<category><![CDATA[yahoo search]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/2009/08/13/i-am-lucky-to-get-the-new-layout/</guid>
		<description><![CDATA[
I am lucky to get the new layout, originally uploaded by Terence Yim.
Though a little bit off topic, looks like it starts rolling out.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=43&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div style="text-align:left;padding:3px;"><a title="photo sharing" href="http://www.flickr.com/photos/chtyim/3819063073/"><img style="border:solid 2px #000000;" src="http://farm3.static.flickr.com/2561/3819063073_ae508f14fc.jpg" alt="" /></a></p>
<p><span style="font-size:.8em;margin-top:0;"><a href="http://www.flickr.com/photos/chtyim/3819063073/">I am lucky to get the new layout</a>, originally uploaded by <a href="http://www.flickr.com/people/chtyim/">Terence Yim</a>.</span></div>
<p>Though a little bit off topic, looks like it starts rolling out.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=43&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2009/08/13/i-am-lucky-to-get-the-new-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2561/3819063073_ae508f14fc.jpg" medium="image" />
	</item>
		<item>
		<title>Adding ping() function to PDO</title>
		<link>http://terenceyim.wordpress.com/2009/01/09/adding-ping-function-to-pdo/</link>
		<comments>http://terenceyim.wordpress.com/2009/01/09/adding-ping-function-to-pdo/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 00:36:45 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/?p=36</guid>
		<description><![CDATA[Recently helped my colleague to add the missing mysqli_ping() function to PDO object in PHP. If anyone missed it, here it is:
&#60;?php
class NPDO {
    private $pdo;
    private $params;

    public function __construct() {
        $this-&#62;params = func_get_args();
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=36&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently helped my colleague to add the missing <a href="http://us3.php.net/manual/en/mysqli.ping.php"><code>mysqli_ping()</code></a> function to PDO object in PHP. If anyone missed it, here it is:</p>
<pre>&lt;?php
class NPDO {
    private $pdo;
    private $params;

    public function __construct() {
        $this-&gt;params = func_get_args();
        $this-&gt;init();
    }

    public function __call($name, array $args) {
        return call_user_func_array(array($this-&gt;pdo, $name), $args);
    }

    <span style="color:#339966;">// The ping() will try to reconnect once if connection lost.
</span>    public function ping() {
        try {
            $this-&gt;pdo-&gt;query('SELECT 1');
        } catch (PDOException $e) {
            $this-&gt;init();  <span style="color:#339966;">// Don't catch exception here, so that re-connect fail will throw exception</span>
        }

        return true;
    }

    private function init() {
        $class = new ReflectionClass('PDO');
        $this-&gt;pdo = $class-&gt;newInstanceArgs($this-&gt;params);
    }
}
?&gt;</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=36&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2009/01/09/adding-ping-function-to-pdo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>
	</item>
		<item>
		<title>Stupid programming</title>
		<link>http://terenceyim.wordpress.com/2008/12/12/stupid-programming/</link>
		<comments>http://terenceyim.wordpress.com/2008/12/12/stupid-programming/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 00:37:00 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[javascript "bad programming"]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/?p=15</guid>
		<description><![CDATA[Just come across a stupid piece of JS program today in some web site:
function preselectSS(what)
{
  if (what == 1) document.getElementById("selSS").selectedIndex = 0;
  else if (what == 2) document.getElementById("selSS").selectedIndex = 1;
  else if (what == 3) document.getElementById("selSS").selectedIndex = 2;
  else document.getElementById("selSS").selectedIndex = 3;
}
Isn&#8217;t it a lot nicer to write it as
function preselectSS(what) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=15&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Just come across a stupid piece of JS program today in some web site:</p>
<pre>function preselectSS(what)
{
  if (what == 1) document.getElementById("selSS").selectedIndex = 0;
  else if (what == 2) document.getElementById("selSS").selectedIndex = 1;
  else if (what == 3) document.getElementById("selSS").selectedIndex = 2;
  else document.getElementById("selSS").selectedIndex = 3;
}</pre>
<p>Isn&#8217;t it a lot nicer to write it as</p>
<pre>function preselectSS(what) {
    document.getElementById("selSS").selectedIndex = (what &gt; 0 &amp;&amp; what &lt;= 3) ? (what - 1) : 3;
}</pre>
<p>The world is full of stupid programmers writing stupid programs.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=15&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2008/12/12/stupid-programming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>
	</item>
		<item>
		<title>Cross domain connection manager with same calling mechanism as YUI</title>
		<link>http://terenceyim.wordpress.com/2008/01/02/cross-domain-connection-manager-with-same-calling-mechanism-as-yui/</link>
		<comments>http://terenceyim.wordpress.com/2008/01/02/cross-domain-connection-manager-with-same-calling-mechanism-as-yui/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 08:24:05 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[asyncRequest]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[Cross domain]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/2008/01/02/cross-domain-connection-manager-with-same-calling-mechanism-as-yui/</guid>
		<description><![CDATA[Update: The same functionality is now provided by the Yahoo! YUI Get Utility.
Update 2: Since the domain I used to host the file is not longer exist, I just paste the JS at the end of the post.
The YUI connection manager use XMLHttpRequest to make remote call, hence calling cross domain URL is prohibited by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=12&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Update: </strong>The same functionality is now provided by the Yahoo! <a href="http://developer.yahoo.com/yui/get/">YUI Get Utility</a>.</p>
<p><strong>Update 2:</strong> Since the domain I used to host the file is not longer exist, I just paste the JS at the end of the post.</p>
<p>The <a href="http://developer.yahoo.com/yui/connection/">YUI connection manager</a> use <code>XMLHttpRequest</code> to make remote call, hence calling cross domain URL is prohibited by the browser security model. This class is to solve this situation without the need to setup any server side proxy, while maintaining the same calling mechanism as the YUI connection manager.</p>
<p><strong>Script source:</strong> <span style="text-decoration:line-through;"><a href="http://rockstonesand.com/js/crossdomainmanager.js">http://rockstonesand.com/js/crossdomainmanager.js</a></span></p>
<p><strong>Minified version:</strong> <span style="text-decoration:line-through;"><a href="http://rockstonesand.com/js/crossdomainmanager_min.js">http://rockstonesand.com/js/crossdomainmanager_min.js</a></span></p>
<p><strong>Usage:</strong> Same as <a href="http://developer.yahoo.com/yui/connection/#async">YUI connection manager</a></p>
<p><strong>Functions supported:</strong></p>
<pre>asyncRequest, isCallInProgress, abort</pre>
<p><strong>Example:</strong><br />
<em>Client side:</em></p>
<div style="border:1px solid grey;">
<pre><span style="color:#008000;">&lt;script src="http://rockstonesand.com/js/crossdomainmanager_min.js"&gt;&lt;/script&gt;
&lt;script&gt;
// Same callback object definition as YUI connection manager
var callback = {
    success: function(obj) {
        var response = obj.responseText;
        // Do UI updates
    },
    failure: function(obj) {
    }
};
var txId = CrossDomainConnect.asyncRequest(
   "http://api.flickr.com/services/feeds/photos_public.gne?lang=en-us&amp;format=json",
   callback,
   "jsoncallback");
&lt;/script&gt;</span></pre>
</div>
<p><strong>Limitations:</strong></p>
<ul>
<li>Only GET method is supported, as it uses script tag hack</li>
<li>The target server side script must support an additional &#8220;callback&#8221; parameter for the connection manager to specify a callback function.<span id="more-12"></span></li>
</ul>
<p><strong>The crossdomainmanager.js:</strong></p>
<div style="border:1px solid grey;">
<pre><span style="color:#000080;">
var CrossDomainConnect = {

    seqNo : 0,
    scriptNodeMap : {},

    asyncRequest : function(url, callback, callbackName) {

        // The URL must support a "callback" parameter
        if (!callbackName) {
            callbackName = "callback";
        }

        var responseName = "response" + this.seqNo;
        this.seqNo++;

        if (url.indexOf('?') === -1) {
            url += "?" + callbackName + "=CrossDomainConnect." + responseName;
        } else {
            url += "&amp;" + callbackName + "=CrossDomainConnect." + responseName;
        }

        // Create the script node
        var node = document.createElement("script");
        node.setAttribute('src', url);

        this.scriptNodeMap[responseName] = node;

        var responseObj = { tId : responseName };
        if (callback.argument) {
            responseObj.argument = callback.argument;
        }

        var timeoutId = null;

        // Bind the response function
        this[responseName] = function(str) {
            delete this[responseName];
            delete this.scriptNodeMap[responseName];

            if (timeoutId) {
                clearTimeout(timeoutId);
            }

            // Must use setTimeout, otherwise may cause crashes in IE6
            setTimeout(function() {
                node.parentNode.removeChild(node);
            }, 0);

            responseObj.status = 200;
            responseObj.responseText = str;

            if (callback.scope) {
                callback.success.call(callback.scope, responseObj);
            } else {
                callback.success(responseObj);
            }
        };

        // Setup timeout function
        if (callback.timeout) {
            var that = this;
            var timeoutFunc = function() {
                that.abort(responseName, callback);
            };

            // Set the timeout
            timeoutId = setTimeout(timeoutFunc, callback.timeout);
        }

        var p = document.getElementsByTagName("head")[0] || document.body;

        p.appendChild(node);

        return responseName;
    },

    isCallInProgress : function(txId) {
        return this.hasOwnProperty(txId);
    },

    abort : function(txId, callback) {
        if (this[txId]) {
            var node = this.scriptNodeMap[txId];

            setTimeout(function() {
                node.parentNode.removeChild(node);
                node = null;
            }, 0);

            delete this[txId];
            delete this.scriptNodeMap[txId];

            if (callback) {
                var responseObj = { tId : txId };
                if (callback.argument) {
                    responseObj.argument = callback.argument;
                }

                responseObj.status = -1;
                responseObj.statusText = "transaction aborted";

                if (callback.scope) {
                    callback.failure.call(calback.scope, responseObj);
                } else {
                    callback.failure(responseObj);
                }
            }

            return true;
        }

        return false;
    }
};</span></pre>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/terenceyim.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/terenceyim.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=12&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2008/01/02/cross-domain-connection-manager-with-same-calling-mechanism-as-yui/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>
	</item>
		<item>
		<title>The Bubbling Technique &amp; Custom Event in YUI</title>
		<link>http://terenceyim.wordpress.com/2007/10/25/the-bubbling-technique-custom-event-in-yui/</link>
		<comments>http://terenceyim.wordpress.com/2007/10/25/the-bubbling-technique-custom-event-in-yui/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 15:35:53 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/2007/10/25/the-bubbling-technique-custom-event-in-yui/</guid>
		<description><![CDATA[Good framework for applying MVC design in Web Application.
http://yuiblog.com/blog/2007/09/13/bubbling-library-by-caridy/
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=9&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Good framework for applying MVC design in Web Application.</p>
<p><a href="http://yuiblog.com/blog/2007/09/13/bubbling-library-by-caridy/">http://yuiblog.com/blog/2007/09/13/bubbling-library-by-caridy/</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/terenceyim.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/terenceyim.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=9&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2007/10/25/the-bubbling-technique-custom-event-in-yui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript that crashes IE</title>
		<link>http://terenceyim.wordpress.com/2007/10/09/javascript-that-crashes-ie/</link>
		<comments>http://terenceyim.wordpress.com/2007/10/09/javascript-that-crashes-ie/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 03:49:19 +0000</pubDate>
		<dc:creator>terenceyim</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[IE crash]]></category>
		<category><![CDATA[script tag hack]]></category>

		<guid isPermaLink="false">http://terenceyim.wordpress.com/2007/10/09/javascript-that-crashes-ie/</guid>
		<description><![CDATA[Recently I was helping my colleague to fix a strange bug in his Javascript. The bug behave like this:

Open the web page in IE.
After everything are loaded (HTML, images, scripts, &#8230;), click on address bar and press enter
IE crashed  

When I try to identify the bug, I&#8217;ve created a simple page that can reproduce [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=4&subd=terenceyim&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently I was helping my colleague to fix a strange bug in his Javascript. The bug behave like this:</p>
<ol>
<li>Open the web page in IE.</li>
<li>After everything are loaded (HTML, images, scripts, &#8230;), click on address bar and press enter</li>
<li>IE crashed <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </li>
</ol>
<p>When I try to identify the bug, I&#8217;ve created a simple page that can reproduce the bug.</p>
<p><font color="#ff0000">crash.html</font></p>
<pre><font color="#339966">&lt;<span class="start-tag">div</span><span class="attribute-name"> id</span>=<span class="attribute-value">"panel"</span>&gt;&lt;/<span class="end-tag">div</span>&gt;
&lt;<span class="start-tag">a</span><span class="attribute-name"> href</span>=<span class="attribute-value">"#" </span><span class="attribute-name">onclick</span>=<span class="attribute-value">"loadScript(); return false;"</span>&gt;Load script&lt;/<span class="end-tag">a</span>&gt;

&lt;<span class="start-tag">script</span>&gt;
    var n = 0;
    var callback = function() {
        n++;
        var panel = document.getElementById("panel");
        panel.innerHTML = "loadScript called " + n + " times.";
        var node = document.getElementById("testid");
        node.parentNode.removeChild(node);
    }

    var loadScript = function() {
        var node = document.createElement("script");
        node.src="crash.js";
        node.id = "testid";

        document.getElementsByTagName("head")[0].appendChild(node);
    }

    window.onload = loadScript;
&lt;/<span class="end-tag">script</span>&gt;</font></pre>
<p><span id="more-4"></span><font color="#ff0000"> crash.js</font></p>
<pre><!--more--><font color="#339966">callback();</font></pre>
<p><!--more-->What the page does is to create a script node dynamically and insert into the document to load an external .js file. When the external &#8220;crash.js&#8221; is loaded, it calls a function to update the page content and remove the script node. IE will be crashed by either click on the address and hit enter button or just click on the link &#8220;Load script&#8221;.</p>
<p>The actual reason why IE crashes on this situation is unknown, but one thing can be sure is it only crashes if the same URL is being requested. If you try to append a dummy random query to the script src URL, IE is working fine.</p>
<p>I&#8217;ve also discovered another way, which I think is better in solving this problem. Simply use a setTimeout() function to wrap around the removeChild statement with timeout = 0.</p>
<pre><!--more--><font color="#339966">setTimeout(function() {
</font><font color="#339966">    var node = document.getElementById("testid");
    node.parentNode.removeChild(node);
}, 0);</font></pre>
<p>The problem will be gone by doing this.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/terenceyim.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/terenceyim.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/terenceyim.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/terenceyim.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/terenceyim.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/terenceyim.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/terenceyim.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/terenceyim.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/terenceyim.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/terenceyim.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/terenceyim.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/terenceyim.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=terenceyim.wordpress.com&blog=1872500&post=4&subd=terenceyim&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://terenceyim.wordpress.com/2007/10/09/javascript-that-crashes-ie/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6ca44c6e23cffd81d5078114ea302184?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Terence</media:title>
		</media:content>
	</item>
	</channel>
</rss>