Login Register

SOLVED: Fix for dojo.addOnLoad with IE (Dojo 1.1)

Hello,

I've recently bumped into a dojo.addOnLoad bug with IE6: It can execute the passed function even if document's readystate is currently "loading".

Here's a way to patch dojo.addOnLoad:

    //dojo.addOnLoad patch if IE
    if(dojo.isIE){
        //Saving a copy of the original function.
        var origAddOnLoad=dojo.addOnLoad;
        //Wrapping it.
        dojo.addOnLoad=function(){
            var args=arguments;
            if(document.readyState=="complete"){
                //Document is loaded. Removing the wrapper.
                dojo.addOnLoad=origAddOnLoad;
                dojo.addOnLoad.apply(dojo,args);
            }else{
                //Document not loaded yet. Deferring execution.
                setTimeout(function(){dojo.addOnLoad.apply(dojo,args);},10);
            }
        };
    }

This code should be put in your own dojo module. So dojo might be in memory right before this patch is executed.

Pascal.

If you can file a test case

If you can file a test case at http://trac.dojotoolkit.org, that would be appreciated. We would like to fix the issue in the toolkit if we have a test case to confirm the fix. You can use the login/password of guest/guest to create a ticket and upload the test case.

Done