Javascript Function

Javascript Tutorials, Ajax , Validation, Calculator, DOM

« Object Oriented Javascript Hello World »

Netscape 4 DOM

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

Post comment:

◎welcome to give out your point。

Calendar

Comments

Previous

Powered By http://www.javascriptfunction.com Godaddy Promo Code

Copyright http://www.javascriptfunction.com/. All Rights Reserved.