Learn Javascript
Document Object Model
Join the Discussion
More of this Tutorial
Document Object Model Internet Explorer DOM Standard DOM Cross Browser DOM Quiz Yourself
Introduction
At about the same time that Microsoft developed the Internet Explorer DOM, Netscape also developed their own completely different DOM. This DOM is known as the Netscape DOM or Layers DOM because it is accessed using document.layers.
This DOM is the only one supported by Netscape 4. It is not supported by any other browser. You should not use this DOM unless you specifically need to cater for Netscape 4 users.
The Layers DOM
This DOM can be used to access any object within your web page but with the exception of anchor tags <a> the ability to manipulate the objects are rather limited.
To access objects within the field you must first provide them with an identifier so that the DOM can reference them. How you do this depends on what type of object you want to reference. Image objects <img> are labelled using the name attribute while all other objects on the page are labelled using the id attribute.
Once your object has been labelled you can then reference that object using the DOM as follows:
Just substitute your label for the label reference in the example. You can then access some of the methods and properties associated with that object on the page by attaching the method or property reference to the end of the object reference. For example to access the 'value' property associated with an object labelled 'myobj' you would use:
The DOM also allows you to access and (in some cases) change the style associated with the object via any attached stylesheets. For example you would access the 'top' positioning of the above object using:
Using What You Know
From what we looked at in the previous tutorial on the Internet Explorer DOM you would probably expect that the best way to check if this DOM is supported is to check for document.layers. In this instance that is not the preferred way of checking if this DOM is supported since Netscape 4 actually contains a bug that will return a wrong result in some situations. Since this DOM is only supported by Netscape 4 we can instead test directly for that particular browser.
&& (parseInt(navigator.appVersion) ==4));

