Javascript Page
Javascript Page
This will always print.
===== Getting a reference for an element in any browser=====
* The standard way is document.getElementById("elemID")
* IE uses document.all("elemID")
* Older Netscape browsers used document.layers[elemID]
* A utility function to get the proper element reference, regardless of browser:
function getElem(elemID){
if(document.all){
return document.all(elemID);
}else if(document.getElementById){
return document.getElementById(elemID);
}else if(document.layers){
return document.layers[elemID];
}
}
...before doing anything with the object, you can make sure you have a valid object like this:
var elem = getElem("SomeElementId");
if(elem){
// elem is valid, so proceed with code
}
===== Commenting =====
===== Linking to an external script file =====
// in the section of an html page
===== Testing for existence of a property or method =====
if(elem && typeof elem.property != "undefined"){
// element property is valid - it is safe to use this property
}
if(elem && typeof elem.method != "undefined"){
// element method is valid - it is safe to call this method
}