I have a very peculiar situation.
I'm debugging a problem in a web app written in a fairly complicated (and slow) framework.
As part of the code, it loads and runs the following script in YUI:
function() {
YU.Event.onDOMReady(function() { init(); });
}
where init()
is a JS function.
PROBLEM: Sometimes (about 1/2 time), when init() function is called, the DOM doesn't yet seem to be loaded. More precisely, document.getElementById();
calls return null
value, and when I load up Internet Explorer debugger (IE8), and breakpoint on the line that does getElementById()
call, the HTML tab of the debugger merely says "Loading..."
(the app is not compatible with FireFox so I can't use Firebug)
I would appreciate any ideas on why this might be happening (only 50% of time) and how to approach investigating this.
if this helps, the problem started when someone made a change to the app, which involved adding a couple of things to the DOM dynamically via appendChild()
Please note that I'm looking specifically for how to address premature onDOMReady()
call, NOT workarounds like "call getElementById()
in a loop with setTimeout till non-null)
The problem is specific to IE8. It went away on IE10.
I fixed it by adding a small wait loop. Interestingly, the loop didn't need to be long (couple milliseconds) - I'm at a loss as to WHY this fixed the issue on IE8, but it did.