Netscape 4 Treats Layers as Separate Documents
<div id="myLayer1"><img name="myImage" src="imageFile.gif"></div>
Now, if we wanted to access that image file. In order to do this, our first inclination would be to use:
document.images["myImage"]
And this would be right in IE 4+ and NS 6; however, in Netscape 4, it treats layers as whole new documents, so in Netscape 4, we'd have to first "access the document the image is in" and use:
document.layers["myLayer1"].document.images["myImage"]
Now, let's change the following image file's src to "someOtherImage.gif"
<div id="myLayer1"><div id="myLayer2"><img name="myImage" src="imageFile.gif"></div></div>
Well, you'd have to use the following code:
if(document.layers){
document.layers["myLayer1"].document.layers["myLayer2"].document.images["myImage"].src="someOtherImage.gif";
}else{
document.images["myImage"].src="someOtherImage.gif";
}
Also note that for Netscape 4, we also could have shortened the code and used:
document.myLayer1.document.myLayer2.document.myImage.src="someOtherImage.gif"
Just in case you feel like it's necessary to use shorter code or you see that somewhere else, you know what it means. Let's now look at statically positioned layers that work in all browsers (yes, even Netscape 4).
