Section 25.147. HTMLDocument: the root of an HTML document tree


25.147. HTMLDocument: the root of an HTML document tree

DOM Level 0: Node Document HTMLDocument

25.147.1. Properties


Element[] all [IE 4]

This nonstandard property is an array-like object that provides access to all HTMLElements in the document. The all[] array originated in IE4, and although it has been superseded by methods such as Document.getElementById( ) and Document.getElementsByTagName( ), it is still used in deployed code. See HTMLDocument.all[] for further details.


readonly HTMLCollection anchors

An array (HTMLCollection) of all Anchor objects in the document.


readonly HTMLCollection applets

An array (HTMLCollection) of all Applet objects in a document.


HTMLElement body

A convenience property that refers to the HTMLElement that represents the <body> tag of this document. For documents that define framesets, this property refers to the outermost <frameset> tag instead.


String cookie

Allows cookies to be queried and set for this document. See HTMLDocument.cookie for details.


String domain

The domain name of the server from which the document was loaded, or null if there is none. This property can also be used to ease the same-origin security policy in specific circumstances. See HTMLDocument.domain for details.


readonly HTMLCollection forms

An array (HTMLCollection) of all Form objects in the document.


readonly HTMLCollection images

An array (HTMLCollection) of Image objects in the document. Note that for compatibility with the Level 0 DOM, images defined with an <object> tag instead of the <img> tag are not included in this collection.


readonly String lastModified

Specifies the date and time of the most recent modification to the document. This value comes from the Last-Modified HTTP header that is optionally sent by the web server.


readonly HTMLCollection links

An array (HTMLCollection) of all Link objects in the document.


readonly String referrer

The URL of the document that linked to this document, or null if this document was not accessed through a hyperlink. This property allows client-side JavaScript to access the HTTP referer header. Note the spelling difference, however: the HTTP header has three r's, and the JavaScript property has four r's.


String title

The contents of the <title> tag for this document.


readonly String URL

The URL of the document. This value is often the same as the location.href property of the Window that contains the document. When URL redirection occurs, however, this URL property holds the actual URL of the document, and location.href holds the URL that was requested.

25.147.2. Methods


close( )

Closes a document stream opened with the open( ) method, forcing any buffered output to be displayed.


getElementsByName( )

Returns an array of nodes (a NodeList) of all elements in the document that have a specified value for their name attribute.


open( )

Opens a stream to which new document contents may be written. Note that this method erases any current document content.


write( )

Appends a string of HTML text to an open document.


writeln( )

Appends a string of HTML text followed by a newline character to an open document.

25.147.3. Description

This interface extends Document and defines HTML-specific properties and methods. A number of the properties are HTMLCollection objects (essentially read-only arrays that can be indexed by number or name) that hold references to anchors, forms, links, and other important scriptable elements of the document. These collection properties originated with the Level 0 DOM. They have been superseded by Document.getElementsByTagName( ) but remain in common use because they are so convenient.

The write( ) method is notable: it allows a script to insert dynamically generated content into a document while the document is being loaded and parsed.

Note that in the Level 1 DOM, HTMLDocument defined a very useful method named getElementById( ). In the Level 2 DOM, this method has been moved to the Document interface, and it is now inherited by HTMLDocument rather than defined by it. See Document.getElementById( ) for details.

25.147.4. See Also

Document, Document.getElementById( ), Document.getElementsByTagName( )




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net