JS: Attach body onload cross browser (methods comparison)
<p>I have examined <a href="http://dean.edwards.name/weblog/2006/06/again/" rel="nofollow">Dean Edward's <code>onload</code> post</a> and have a question: what's wrong with this <code>onload</code> attaching method? Where and why can it fail? And when is it safe to use this simpler function?</p>

<pre><code>function addLoadEvent(func){
    var oldonload = window.onload;
    if(typeof window.onload != 'function'){
        window.onload = func;
    }else{
        window.onload = function(){
            oldonload();
            func();
        }
    }
}
</code></pre>
