|
PART II Chapter 6
The HTML Document
The structure, contents, and style of an HTML document are exposed
through the document property on the window. The
document property references an object that encapsulates all the information about the document. The
document object is the most important and powerful object of the Dynamic HTML object
model. Through this object, all elements contained in the document can fire events and
can be accessed and modified by scripts, allowing you to create a dynamic document.
The elements in the HTML document are exposed through the collections
on the document object. The contents of the document are accessible through
these elements and through a TextRange object. Both techniques allow you to access
and change the contents. The style of the document is exposed through the
styleSheets collection, which provides access to the global and linked style sheets
associated with the document.
Our discussion of these issues will span several chapters. This chapter
begins the discussion by covering the following topics:
- Referencing the document object The document object is a
property of the window. This section shows you how to access the HTML
document contained within the current window as well as documents
displayed in other windows.
- Changing the document's colors The document object exposes properties for manipulating the color of the text and background on the page. These properties are compatible with the existing object
model implementations in Netscape Navigator and Microsoft Internet
Explorer 3.0.
- Accessing meta information about the document Information derived while the document is downloaded is exposed to the object model. This meta information includes the initial file size of the
document and the dates when the file was created and last modified. In addition,
any cookies associated with the document can be retrieved or assigned.
- Modifying the HTML stream The document object exposes methods for manipulating the HTML stream while the page is loading.
These methods work only while a page is rendering and are not used to modify a page once it is loadedseparate objects and methods are exposed for this purpose.
Figure 6-1 shows the document object and the collections it contains. Next
to each collection is the tag for the HTML elements it contains.
Figure 6-1. The document object's collections and the corresponding HTML elements. [Содержание]
|