Ticket #6741 (closed defect: invalid)
Function registered with dojo.addOnLoad is executed before document loaded on IE6.0.2900
| Reported by: | guest | Owned by: | jburke |
|---|---|---|---|
| Priority: | high | Milestone: | 1.2 |
| Component: | Core | Version: | 1.1.0 |
| Severity: | major | Keywords: | dojo addOnLoad document IE IE6 |
| Cc: | pbarbier@… |
Description
From pbarbier at novell dot com (Pascal Barbier).
Bug occurs only with IE6.0.2900 (maybe with more recent IE6 versions but not tested).
Bug does not occur with Firefox and IE7.
No direct error message, but if the registered function performs a innerHTML="" or an appendChild, you'll get a 'Operation Aborted' error or a browser crash.
Test case to reproduce the bug: 1) Have a custom dojo module such as:
mymodule/common.js:
/* Begin file content */ dojo.provide("mymodule.common");
mymodule={};
dojo.addOnLoad(function(){
alert(document.readyState);
}); /* End file content */
2) Have a custom build of dojo 1.1 from this profile:
dependencies.layers.push({
name: "dojo.js", dependencies: [
"dojo.date.stamp", "dojo.parser", "dojo.string", "dojo.i18n", "dojo.regexp", "dojo.cookie", "dojox.collections.ArrayList?", "dojox.collections.Stack", "dojox.fx", "dijit.dijit", "dijit.form.Button", "dijit.Menu", "dijit.layout.StackContainer?", "dijit.layout.TabContainer?", "dijit.layout.ContentPane?", "dijit.layout.LayoutContainer?", "dijit.Tree", "mymodule.common"
]});
dependencies.prefixes.push(
["dojo", "../../dojo"], [ "dojox", "../dojox"], [ "dijit", "../dijit"]); [ "mymodule", "../mymodule"]);
3) Setup a html page where the custom build from step 2 is referenced in the page <head>
4) Open the page in IE6
You'll get a alert box which content is "interactive".
With IE7, the alert box will read "complete".
When document readyState is "interactive", it is not yet loaded completely. Hence the bug.
Current workaround for this bug, to be placed at the very beginning of the custom module (after dojo.provide):
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);
}
};
}