The question is so like a zillion others here and on the web - How to check if DOM has loaded in Javascript? But here\'s the catch:
If relying on document.readyState is ok, quick-and-dirty solution with polling:
document.readyState
(function() { var state = document.readyState; if(state === 'interactive' || state === 'complete') { // do stuff } else setTimeout(arguments.callee, 100); })();