When you load a page in Navigator, it creates a number of objects corresponding to the page, its contents, and other pertinent information.
Every page always has the following objects:
The properties of the document object are largely content-dependent. That is, they are created based on the content that you put in the document. For example, the document object has a property for each form and each anchor in the document.
For example, suppose you create a page named simple.html that contains the following HTML:
As always, there would be window, location, history, and document objects. These would have properties such as:
These are just some example values. In practice, these values would be based on the document's actual location, its title, foreground and background colors, and so on.
Navigator would also create the following objects based on the contents of the page:
These would have properties such as:
Notice that each of the property references above starts with "document," followed by the name of the form, "myform," and then the property name (for form properties) or the name of the form element. This sequence follows the Navigator's object hierarchy, discussed in the next section.
The objects in Navigator exist in a hierarchy that reflects the hierarchical structure of the HTML page itself. Although you cannot derive object classes from these objects, as you can in languages such as Java, it is useful to understand the Navigator's JavaScript object hierarchy. In the strict object-oriented sense, this type of hierarchy is known as an instance hierarchy, since it concerns specific instances of objects rather than object classes.
In this hierarchy, an object's "descendants" are properties of the object. For example, a form named "form1" is an object, but is also a property of document, and is referred to as "document.form1". The Navigator object hierarchy is illustrated below:
To refer to specific properties of these objects, you must specify the object name and all its ancestors. Exception: You are not required to include the window object.
To use JavaScript properly in the Navigator, it is important to have a basic understanding of how the Navigator performs layout. Layout refers to transforming the plain text directives of HTML into graphical display on your computer. Generally speaking, layout happens sequentially in the Navigator. That is, the Navigator starts from the top of the HTML file and works its way down, figuring out how to display output to the screen as it goes. So, it starts with the HEAD of an HTML document, then starts at the top of the BODY and works its way down.
Because of this "top-down" behavior, JavaScript only reflects HTML that it has encountered. For example, suppose you define a form with a couple of text input elments:
There would be a JavaScript object named myform based on this form. The form would have a property corresponding to the text object, that you would refer to as
The forms in a document are stored in an array called forms. The first (topmost in the page) form is forms[0], the second forms[1], and so on. So the above references could also be:
Likewise, the elements in a form, such as text fields, radio buttons, and so on, are stored in an elements array.
The window object is the "parent" object for all other objects in Navigator. You can always omit the object name in references to window properties and methods.
Window has several very useful methods that create new windows and pop-up dialog boxes:
The window object has properties for all the frames in a frameset. The frames are stored in the frames array. The frames array contains an entry for each child frame in a window. For example, if a window contains three child frames, these frames are reflected as window.frames[0], window.frames[1], and window.frames[2].
The status property enables you to set the message in the status bar at the bottom of the client window.