onDomReady problem with IE
In our webapplication we're using an overlaying Div to prevent users from sending a submit before site is loaded completely.
To do this we use the DOMContentLoaded-event of webbrowser. When DOM is completed the Div should disappear and user can start working.
Everything works fine in Firefox. Because IE doesn't support the DOMContentLoaded-event we use the defer-attribute for a script, which is loaded at the end of page.
Following sourcecode is used:
domready.js:
window.onDomReady = DomReady;
//Setup the event
function DomReady(fn)
{
//W3C
if(document.addEventListen
er)
{
document.addEventListener(
"DOMConten
tLoaded", fn, false);
}
//IE
else
{
if(document.all)
{
document.write('<script type="text/javascript" defer="defer" src="ie_onload.js"><\/scri
pt>');
}
var oldLoad = window.onload;
var newLoad = oldLoad ? function(){fn.call(this);o
ldLoad.cal
l(this);} : fn;
window.onload = newLoad;
}
}
ie_onload.js:
hideModalDialog();
In page-source the domready.js is loaded in header. In body following code shows up the overlaying Div and setups the defined onDomReady-attribut to hide the Div:
<script type="text/javascript">
showModalDialog();
window.onDomReady(function
(){hideMod
alDialog()
;});
</script>
Now the problem: In 100% of loading pages in Firefox the page is loaded correctly and the Div disappears after loading. The same works fine in IE, but in 0,01% of all loadings the Div
never disappears and user can't interact. The statusbar shows "Done" for page. When reloading the page the site is loaded correctly. We use a template system and the code for showing and hiding the Div is included everywhere. But the problem can't be located to a single page it appears randomly and is very hard to reproduce.
Newest investigations show the problem appears more often when loading sites in low-bandwiths e.g. UMTS.
In former versions of our DomReady-function we used the .onreadystatechange instead of defer-attribute but the loading-problems had appeared more often.
We need a solution for all versions of IE >=Version 6.