I've encountered a strange issue with IE8 recently. My code has been functioning properly for a while and still works perfectly in Firefox, but all of a sudden Prototype has stopped calling my event listeners for dom:loaded
.
I typically attach them using
document.observe("dom:loaded", callback);
After some frustrating debugging (thanks IE debugger!), I've determined that Prototype's fireContentLoadedEvent
function (line 4102) is being triggered way before the DOM is fully loaded (almost immediately after the document.write("<script...")
).
fireContentLoadedEvent
is actually called from the handler for when !document.addEventListener
ie (see prototype.js line 4125)
...
if (document.addEventListener) {
...
} else {
document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
$("__onDOMContentLoaded").onreadystatechange = function() {
if (this.readyState == "complete") {
this.onreadystatechange = null;
fireContentLoadedEvent();
}
};
}
...
Can anyone familiar with this process shed some light on why it might be triggering prematurely?