1. Home
  2. Computing & Technology
  3. JavaScript

Learn Javascript

Document Object Model

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:

document.layers['label']

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:

document.layers['myobj'].value

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:

document.layers['myobj'].top

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.

var nsDOM = ((navigator.appName.indexOf('Netscape') != -1)
&& (parseInt(navigator.appVersion) ==4));

Past Lessons

  1. Introduction
  2. Decision Making
  3. Functions
  4. Maintain and Test
  5. External Script and Noscript
  6. Object Oriented Javascript
  7. Loops
  8. More Predefined Classes
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.