Archive for the ‘Javascript’ Category
How to detect if HTML document has fully initialized
Posted by: admin in Javascript on November 27th, 2011
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
‘null’ is null or not an object
Posted by: admin in Javascript on May 18th, 2010
This error occurs when the object/element you are trying to access does not exists in the html page or you did not specify the ID of the element.
or
You are executing a code while the html page has not yet fully loaded. If you need to execute a certain code during page load, this can be done on window.onload event or put the script before the end of the body tag