Datasheet
Chapter 1: Introduction to JavaScript
10
The Browser Object Model consists of the following sub - components:
The
document object: Represents the document object of the current page.
The
frames collection: Provides array of the frames within the current page.
The
history object: Contains the history list of the browser.
The
location object: Holds the current URL that the browser is displaying.
The
navigator object: Has information about the browser itself, like the version number, and
browser engine.
The Document Object Model (DOM)
By far the most important object of all the available object models in a browser is the document . The
document gives access to all the elements on a page as a hierarchical collection of nodes. It also contains
some meta information about the page itself such as title and URL and gives access to some short - hand
collections of common elements like forms, links, and
< a > tags (anchors). The document object can be
accessed from any part of a JavaScript application from
window.document , or simply document .
The DOM is a very large object but some of the most common top - level properties can be found as
follows. A more complete reference with full browser support information is in Appendix F.
❑
❑
❑
❑
❑
Document PropertyDescription
body
Returns a reference to the <body> container of the current page,
containing all the HTML on the page.
cookie
Gives read and write access the cookies accessible by this page.
forms[ ]
An array of all the forms on the page, including all the form fields
within them.
links[ ]
An array of all the hyperlinks on the page.
location
Gets and sets the location, or current URL, of the window object.
title
The title of the document (defined in the <title> tag).
Window
history object location navigator objectframes collectiondocument object
Figure 1-3
You ’ ll look at this in more detail later, but for now it ’ s enough to know that the document is a
representation of the current page, is dynamic (can be modified via JavaScript calls), and is not exactly
the same between browser engines. For example, Internet Explorer document object contains methods
CH001.indd 10CH001.indd 10 6/25/09 7:53:18 PM6/25/09 7:53:18 PM