Quantcast
Channel: Powertips » Javascript
Viewing all articles
Browse latest Browse all 10

How to detect if HTML document has fully initialized

$
0
0

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


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images