Most programmers use the “onload” event to detect if the document has fully loaded, but there’s a flaws relying on this technique. The alternative of detecting is to check the DOM tree of the document.
For Firefox and Opera 9+, use “DOMContentLoaded‘
if ( document.addEventListener )
document.addEventListener(“DOMContentLoaded”, myFunction, false);
For Internet Explorer,
if ( document.all && !window.opera ) { //
document.writer( ‘<script type=”text/javascript” id=”contentloadtag” defer=”defer” src=”javascript:void(0)”></script>’);
var contentloadtag = document.getElementById(“contentloadtag”);
contentloadtag.onreadystatechange = function() {
if ( this.readyState == “complete” ) [
myFunction();
}
}
}
Source