document | NN 2 IE 3 DOM 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
The document object represents both the content viewed in the browser window or frame and the other content of the HTML file loaded into the window or frame. Thus, all information from the head portion of the file is also part of the document object. All references to elements must include a reference to the document object. The document object has no name other than its hard-wired object name: document. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
For a browser with internal architecture based closely on the W3C DOM, this document object represents the HTMLDocument objecta special kind (internal subclass) of the core module's Document object, suited to holding HTML documents. In other words, the HTMLDocument object inherits the properties and methods of the core Document object (sharing facilities with XML documents) and gets additional properties and methods that apply only to HTML documents. Of course, there is the conceptual incongruity about whether an HTMLDocument is applicable to an XHTML document because such a document theoretically is an XML document. But, in practice, even an XHTML document becomes an HTML document for scripting purposes, and has all the HTMLDocument properties and methods available to it. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
One more important practical side to a W3C DOM implementation (as evidenced by the Netscape 6 implementation) is that the document object internally implements document-level properties and methods from other DOM modules, such as views, events, and styles. Each of these modules defines an object (DocumentEvent, DocumentRange, DocumentStyle, and DocumentView) that provides a vital connection between the HTMLDocument and these add-on module features. Thus, it is the styleSheets property of the DocumentStyle object in the W3C DOM that the scriptable document object described here uses to reach the styleSheet objects and their rules. And the DocumentEvent object links in its createEvent( ) method that allows the scriptable document object to generate an event outside the normal user- or system-created events. All of these features become subsumed by the document object you reference and script in Netscape 6 and similar browsers. The precise source module for a particular feature is not important to the scripterall you need to know is that the properties and methods belong to the scriptable document object. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Object Model Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[window.]document |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Properties | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Object-Specific Event Handler Properties | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
activeElement | NN n/a IE 4 DOM n/a |
|
Read-only |
Refers to the object that is currently designated as the active element in the document. To learn more about the returned object, you'll need to examine the object's tagName, id, or other properties. Because buttons and other elements do not receive focus on the IE 4 for Macintosh, the returned value of this property may vary with operating system. While an element (especially a form control) that receives focus also becomes active, an element might be active, but due to other settings in newer IE versions, does not have focus. See the shared setActive( ) method. |
|
Example | |
var currObj = document.activeElement; |
|
Value | |
Element object reference. |
|
Default | |
None. |
alinkColor | NN 2 IE 3 DOM n/a |
|
Read/Write (IE) |
Specifies the color of a hypertext link as it is being clicked. The color is applied to the link text or border around an image or object embedded within an a element. See also linkColor and vlinkColor properties for unvisited and visited link colors. Replaced in the W3C DOM by the aLink property of the body object, which is supported in IE 4 and later and in Netscape 6. Dynamically changed values for alinkColor are not reflected on the page in Navigator through Version 4. |
|
Example | |
document.alinkColor = "green"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
#0000FF |
anchors[ ] | NN 2 IE 3 DOM 1 |
|
|
Returns an array of all anchor objects in the current document. This includes a elements that are designed as either anchors or combination anchors and links. Items in this array are indexed (zero-based) in source code order. |
|
Example | |
var aCount = document.anchors.length; |
|
Value | |
Array of anchor element objects. |
|
Default | |
Array of length zero. |
applets[ ] | NN 2 IE 3 DOM 1 |
|
|
Returns an array of all Java applet objects in the current document. An applet must be started and running before it is counted as an object. Items in this array are indexed (zero-based) in source code order. |
|
Example | |
var appletCount = document.applets.length |
|
Value | |
Array of applet element objects. |
|
Default | |
Array of length zero. |
bgColor | NN 2 IE 3 DOM n/a |
|
Read/Write |
Provides the background color of the document. Even if the bgcolor attribute or bgColor property is set with a plain-language color name, the returned value is always a hexadecimal triplet. |
|
Setting the bgColor property of a document in Navigator 2 or 3 for Macintosh or Unix does not properly redraw the window. Window content is obscured by the new color on those platforms. For browsers that support the document.body object, use the bgColor property of that object instead. |
|
Example | |
document.bgColor = "yellow"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
Varies with browser and operating system. |
body | NN 6 IE 4 DOM 1 |
|
Read-only |
Returns a reference to the body object defined by the body element within the document. This property is used as a gateway to the body object's properties. |
|
Example | |
document.body.leftMargin = 15; |
|
Value | |
Object reference. |
|
Default | |
The current body object. |
charset | NN n/a IE 4 DOM n/a |
|
Read/Write |
Indicates the character encoding of the document's content. This property is dropped from IE 6 for Windows in favor of the document.defaultCharset property. For Netscape 6, use the document.characterSet property. |
|
Example | |
if (document.charset == "csISO5427Cyrillic") { // process for Cyrillic charset } |
|
Value | |
Case-insensitive alias from the character set registry (ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets). |
|
Default | |
Determined by browser. |
characterSet | NN 6 IE n/a DOM n/a |
|
Read-only |
Indicates the character encoding of the document's content. |
|
Example | |
if (document.characterSet == "ISO-8859-1") { // process for standard Latin character set } |
|
Value | |
Case-insensitive alias from the character set registry (ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets). |
|
Default | |
Determined by browser. |
compatMode | NN 7 IE 6 DOM n/a |
|
Read-only |
Returns the compatibility mode for the document, as controlled by the DOCTYPE element's content. See the DOCTYPE element discussion in Chapter 8 for details on how to force the browser to treat a document in either backward compatibility or standards compatibility mode for element positioning and other implementation details. Because the choice of mode can impact some style property results, you can use this property to branch between two calculations in a shared library so that they treat the current document correctly, regardless of mode. |
|
Example | |
if (document.compatMode == "BackCompat") { // process as if IE 5.5 or earlier or Netscape "quirks" mode } |
|
Value | |
String constant: BackCompat | CSS1Compat. |
|
Default | |
BackCompat |
defaultCharset | NN n/a IE 4 DOM n/a |
|
Read-only |
Indicates the character encoding of the content of the document. |
|
Example | |
var cset = document.defaultCharset; |
|
Value | |
Case-insensitive alias from the character set registry (ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets). |
|
Default | |
Determined by browser. |
defaultView | NN 6 IE n/a DOM 2 |
|
Read-only |
Returns a reference to the W3C DOM abstract representation of a "viewer" that renders the document (the formal name for the object is AbstractView). In Netscape 6, this object equates to the window or frame object that contains the document. A script function that has access to a document object (such as via the element object's ownerDocument property) can obtain a valid reference to the document's window via this defaultView property. The document's view includes knowledge about cascaded style rules applied to each element. See Chapter 4 for an example of obtaining the effective style of an element with the help of the document.defaultView property and the getComputedStyle( ) method. |
|
This is as close as the W3C DOM Level 2 comes to acknowledging the existence of a window object. More is to come in Level 3. |
|
Example | |
var theWin = elemRef.ownerDocument.defaultView; |
|
Value | |
Reference to a window object. |
|
Default | |
The document's window. |
doctype | NN 6 IE 5(Mac) DOM 1 |
|
Read-only |
Returns a reference to the DOCTYPE element object (the same as the W3C DOM abstract DocumentType node object). The property returns a reference value only if the DOCTYPE is specified in the document; otherwise the property returns null. As of Version 6, IE for Windows does not implement this property or node type. See the DocumentType object for properties available in various browsers. In a pure W3C DOM environment, the doctype property is inherited from the core document object, and is thus available to XML documents, as well. |
|
Example | |
var docsType = document.doctype; |
|
Value | |
Node reference. |
|
Default | |
None. |
documentElement | NN 6 IE 5 DOM 1 |
|
Read-only |
Returns a reference to the root element node of the document. For HTML documents, the reference is to the html element that encompasses the document's head and body elements. In a pure W3C DOM environment, the documentElement property is inherited from the core document object, and is thus available to XML documents, as well. |
|
Example | |
var rootElem = document.documentElement; |
|
Value | |
Element node reference. |
|
Default | |
The current html element object. |
domain | NN 3 IE 4 DOM 1 |
|
Read/Write |
Provides the hostname of the server that served up the document. If documents from different servers on the same domain must exchange content with each other, the domain properties of both documents must be set to the same domain to avoid security restrictions. Normally, if the hosts don't match, browser security disallows access to the other document's form data. This property allows, for example, a page from the www server to communicate with a page served up by a secure server. |
|
Example | |
document.domain = "megaCorp.com"; |
|
Value | |
String of the domain name that two documents have in common (exclusive of the server name). |
|
Default | |
None. |
embeds[ ] | NN 3 IE 4 DOM n/a |
|
|
Returns an array of all embedded objects (embed elements) in the current document. Items in this array are indexed (zero-based) in source code order. |
|
Example | |
var embedCount = document.embeds.length; |
|
Value | |
Array of embed object references. |
|
Default | |
Array of zero length. |
expando | NN n/a IE 4 DOM n/a |
|
Read/Write |
Specifies whether scripts in the current document allow the creation and use of custom properties assigned to the document object. The extensible nature of JavaScript allows scripters to create a new object property by just assigning a value to it (as in document.stooge = "Curly"). This also means the document accepts incorrectly spelled property assignments, such as forgetting to set a middle letter of a long property name to uppercase (marginLeftColor). Such assignments are accepted without question, but the desired result is nowhere to be seen. If you don't intend to create custom properties, consider setting document.expando to false in an opening script statement as you author a page. This could help prevent spelling errors from causing bugs. The setting affects only scripts in the current document. |
|
Example | |
document.expando = false; |
|
Value | |
Boolean value: true | false. |
|
Default | |
true |
fgColor | NN 2 IE 3 DOM n/a |
|
Read/Write |
Provides the foreground (text) color for the document. While you can change this property in all versions of Navigator, the text does not change dynamically in versions prior to 6. Still supported in current browsers, this property is replaced in IE 4 and Netscape 6 by document.body.text or style sheet settings. |
|
Example | |
document.fgColor = "darkred"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
Browser default (usually black). |
fileCreatedDate | NN n/a IE 4(Win) DOM n/a |
|
Read-only |
Returns a string of the date (but not the time) that the server (or local filesystem) reports the currently-loaded file was created. IE 4's value is a long date format, but starting with IE 5, the date information is formatted as mm/dd/yyyy. The value may be corrupted if the server supplies the data in a format that IE does not expect. Not implemented in IE Mac through Version 5.1. |
|
Example | |
var dateObj = new Date(document.fileCreatedDate); |
|
Value | |
Date string. |
|
Default | |
None. |
fileModifiedDate | NN n/a IE 4(Win) DOM n/a |
|
Read-only |
Returns a string of the date (but not the time) that the server (or local file system) reports the currently-loaded file was most recently modified. IE 4's value is a long date format, but starting with IE 5, the date information is formatted as mm/dd/yyyy. The value may be corrupted or incorrect if the server supplies the data in a format that IE does not expect. Not implemented in IE Mac through Version 5.1. |
|
Example | |
var dateObj = new Date(document.fileModifiedDate); |
|
Value | |
Date string. |
|
Default | |
None. |
fileSize | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns the number of bytes for the size of the currently-loaded document. IE for Windows returns this value as a string, while IE for Macintosh returns a number value (an important distinction if you need to perform math operations on the value). |
|
Example | |
var byteCount = parseInt(document.fileSize, 10); |
|
Value | |
Integer as string (Windows) or number (Mac). |
|
Default | |
None. |
fileUpdatedDate | NN n/a IE 5.5(Win) DOM n/a |
|
Read-only |
Returns an empty string. Apparently not officially supported for the document object. |
forms[ ] | NN 2 IE 3 DOM 1 |
|
Read-only |
Returns an array of all form objects (form elements) in the current document. Items in this array are indexed (zero-based) in source code order, but may also be accessed by using the form's name as a string index value. |
|
Example | |
var elemCount = document.forms[0].elements.length; |
|
Value | |
Array of form objects. |
|
Default | |
Array of zero length. |
frames[ ] | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns an array of all iframe objects (iframe element objects, not to be confused with window-like frame objects) in the current document. Items in this array are indexed (zero-based) in source code order. For cross-compatibility with IE 5 and later and Netscape 6, use document.getElementsByTagName("iframe") instead. |
|
Example | |
var iframeCount = document.frames.length; |
|
Value | |
Array of iframe objects. |
|
Default | |
Array of zero length. |
height, width | NN 4 IE n/a DOM n/a |
|
Read-only |
Return the pixel dimensions of the entire rendered document. These values coincide with the offsetHeight and offsetWidth property values for the document.body object. Since neither property pairing is yet sanctioned by the W3C DOM, you might prefer the offset pair, because they are at least cross-browser compatible. |
|
Example | |
var howTall = document.height; |
|
Value | |
Number of pixels. |
|
Default | |
Current document size. |
ids[ ] | NN |4| IE n/a DOM n/a |
|
Read-only |
Used with the Navigator 4-only JavaScript syntax of style sheets, the ids[ ] collection is part of a reference to a single ID and the style property assigned to it in the syntax form [document.]ids.idName.stylePropertyName. For a list of related properties, see the tags object listing in this chapter. |
images[ ] | NN 2 IE 3 DOM 1 |
|
Read-only |
Returns an array of all img element objects (exclusive of pre-cached images loaded via the new Image( ) constructor) in the current document. Items in this array are indexed (zero-based) in source code order, and may be accessed by number or by string name. The presence of this property indicates support for live, swappable images. |
|
Example | |
document.images["home"].src = "images/homeHilite.jpg"; |
|
Value | |
Array of img objects. |
|
Default | |
Array of zero length. |
implementation | NN 6 IE 5(Mac)/6(Win) DOM 1 |
|
Read-only |
Returns a reference to the W3C DOMImplementation object, which represents, to a limited degree, the environment that makes up the document containerthe browser, for our purposes. Methods of the object let you see which DOM modules the browser reports supporting. This object is also a gateway to creating virtual W3C Document and DocumentType objects outside of the current document tree. Thus, in Netscape 6 you can use the document.implementation property as a start to generating a nonrendered document for external XML documents. See the DOMImplementation object for details about the methods and their browser support. |
|
Example | |
var xDoc = document.implementation.createDocument("", "theXdoc", null); |
|
Value | |
Reference to a DOMImplementation object. |
|
Default | |
Current DOMImplementation object. |
lastModified | NN 2 IE 3 DOM n/a |
|
Read-only |
Provides the date and time (as a string) on which the server says the document file was last modified. Some servers don't supply this information at all or correctly. Non-Windows browsers also tend to have a rough time interpreting the information correctly. Only in recent browsers is the date string in a form suitable as a parameter for a Date object constructor. |
|
Example | |
document.write(document.lastModified); |
|
Value | |
String representation of a date and time. |
|
Default | |
None. |
layers[ ] | NN |4| IE n/a DOM n/a |
|
Read-only |
Returns an array of all Navigator 4-only layer element objects in the current document. Also included in the array are references to other HTML elements with style sheets that set the element to be relative- or absolute-positioned (in which case, Navigator 4 treats those elements as layer objects). Items in this array are indexed (zero-based) in source code order, and may be accessed by number or by string name. As a dead-end feature implemented only in Navigator 4, the presence of this property indicates support for the unique referencing requirements for Netscape layers. |
|
Example | |
if (document.layers) { // use document.layers[ ] syntax for references } |
|
Value | |
Array of layer objects or their equivalent. |
|
Default | |
Array of zero length. |
linkColor | NN 2 IE 3 DOM n/a |
|
Read/Write |
Indicates the color of a hypertext link that has not been visited (that is, the URL of the link is not in the browser's cache). This is one of three states for a link: unvisited, active, and visited. The color is applied to the link text or border around an image or object embedded within an a element. Changes to this property do not dynamically change the link color in Navigator 4 or earlier. Starting with IE 4 and Netscape 6, you should switch to using the W3C DOM alternative, document.body.link, or style sheets. |
|
Example | |
document.link Color= "#00FF00"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
#0000FF |
location | NN <6 IE 3 DOM n/a |
|
Read/Write |
Indicates the URL of the current document. This property was deprecated because it may conflict with the window.location property. Netscape 6 drops support for this property entirely. Use either the document.URL property, or, better, the window.location.href property. |
|
Example | |
document.location = "products/widget33.html"; |
|
Value | |
A full or relative URL as a string. |
|
Default | |
Document URL. |
media | NN n/a IE 5.5(Win) DOM n/a |
|
Read/Write |
Returns a string indicating the output medium for which the content is formatted. The property returns an empty string as of IE 6, and throws a security error if you assign accepted string values (all, print, or screen) to it. Avoid using this property with the document object. |
mimeType | NN n/a IE 5(Win) DOM n/a |
|
Read-only |
Returns a string indicating the basic document type, but not in a MIME format. For an HTML document, the string returned changed starting with IE 5.5 to HTML Document. Do not confuse this document object property with the Netscape and IE/Mac navigator.mimeTypes property, which is an entirely different animal. |
|
Example | |
var what = document.mimeType; |
|
Value | |
String. |
|
Default | |
"HTML Document" |
nameProp | NN n/a IE 6(Win) DOM n/a |
|
Read-only |
Returns a string containing the same data as document.title, including an empty string if no title element exists in the document. This property may not be officially supported for the document object. |
|
Value | |
String. |
|
Default | |
Empty string. |
namespaces[ ] | NN n/a IE 5.5(Win) DOM n/a |
|
Read-only |
Returns a collection of IE namespace objects implemented in the current document. A namespace object is a gateway to loading external behaviors. For more details, visit http://msdn.microsoft.com/workshop/author/behaviors/overview/elementb_ovw.asp. |
|
Example | |
var IENSCount = document.namespaces.length; |
|
Value | |
Array of namespace object references. |
|
Default | |
Array of zero length. |
parentWindow | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns a reference to the window object (which may be a frame in a frameset) that contains the current document. Use this reference to access the window's properties and methods directly. The returned value is the same as the window reference from the document. |
|
Example | |
var siblingCount = document.parentWindow.frames.length; |
|
Value | |
window or frame object reference. |
|
Default | |
window object. |
plugins[ ] | NN 4 IE 4 DOM n/a |
|
Read-only |
Returns an array of all embedded objects (embed elements) in the current document. Items in this array are indexed (zero-based) in source code order. Do not confuse this collection with the navigator.plugins collection in Netscape Navigator. |
|
Example | |
var embedCount = document.plugins.length; |
|
Value | |
Array of embed object references. |
|
Default | |
Array of zero length. |
protocol | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns a plain-language string describing the protocol used to load the current document. Unlike the location.protocol property's literal value (e.g., http: or file:), the document.protocol is human-readable (e.g., Hypertext Transfer Protocol or File Protocol). |
|
Example | |
if (document.protocol == "File Protocol") { // process for file access in IE } |
|
Value | |
Plain-language string. |
|
Default | |
Current document's protocol type. |
readyState | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns the current download status of the document content. If a script (especially one initiated by a user event) can perform some actions while the document is still loading, but must avoid other actions until the entire page has loaded, this property provides intermediate information about the loading process. You would use its value in condition tests. The value of this property changes during loading as the loading state changes. Each change of the property value fires an onreadystatechange event. |
|
Example | |
if (document.readyState == "loading") { // statements for alternate handling } |
|
Value | |
One of the following values (as strings): complete | interactive | loading | uninitialized. Some elements may allow the user to interact with partial content, in which case the property may return interactive until all loading has completed. |
|
Default | |
None. |
referrer | NN 2 IE 3 DOM 1 |
|
Read-only |
Returns a string of the URL of the page from which the current page was accessed, provided the original page had a link to the current page. Many server logs capture this information as well. Scripts can see whether the visitor reached the current document from specific origins and perhaps present slightly different content on the page accordingly. If the visitor arrived by another method, such as typing the document URL into a browser dialog or by selecting a bookmark, the referrer property returns an empty string. Many versions of IE for Windows fail to report the correct referrer URL, often showing the URL of the current page instead. |
|
Example | |
if (document.referrer) { document.write("<p>Thanks for following the link to our web site.</p>"); } |
|
Value | |
String. |
|
Default | |
None. |
scripts[ ] | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns an array of all script objects (script elements) in the current document. Each script object may contain any number of functions. The scripts[ ] collection counts the number of actual <script> tags in the document. Items in this array are indexed (zero-based) in source code order. |
|
Example | |
var scriptCount = document.scripts.length; |
|
Value | |
Array of script element references. |
|
Default | |
Array of zero length. |
security | NN n/a IE 5.5(Win) DOM n/a |
|
Read-only |
Returns a string describing the security policy in force for the current document. |
|
Example | |
var secPolicy = document.security; |
|
Value | |
String. |
|
Default | |
"This type of document does not have a security certificate." |
selection | NN n/a IE 4 DOM n/a |
|
Read-only |
Returns a selection object. To work with text that has been selected by the user or script, you must convert the selection to a TextRange object. This is possible only in Internet Explorer for Win32. Access to the Netscape 6 selection is via the window.selection property. |
|
Example | |
var range = document.selection.createRange( ); |
|
Value | |
Object reference. |
|
Default | |
None. |
styleSheets[ ] | NN 6 IE 4 DOM 2 |
|
Read-only |
Returns an array of all styleSheet objects in the current document. Each style object may contain any number of style sheet rules. The styleSheets[ ] collection counts the number of actual <style> tags in the document as well as <link> tags that load external style sheet files. Items in this array are indexed (zero-based) in source code order. An @import style sheet object is accessible via a styleSheet object's cssRule.styleSheet property. See the styleSheet object. |
|
Example | |
for (var i = 0; i < document.styleSheets.length; i++) { // loop through each styleSheet object } |
|
Value | |
Array of styleSheet object references. |
|
Default | |
Array of zero length. |
title | NN 2 IE 3 DOM 1 |
|
Read/Write |
Unlike the title property for objects that reflect HTML elements, the document.title property refers to the content of the title element defined in the head portion of a document. The title content appears in the browser's titlebar to help identify the document. This is also the content that goes into a bookmark listing for the page. Although the property is read/write, don't be surprised if a browser version does not alter the window titlebar in response. |
|
Example | |
document.title = "Fred\'s Home Page"; |
|
Value | |
String. |
|
Default | |
None. |
URL | NN 3 IE 4 DOM 1 |
|
Read/Write |
Provides the URL of the current document. The value is the same as location.href. The document.URL property evolved as a replacement for document.location to avoid potential confusion (by scripters and JavaScript interpreter engines) between the location object and document.location property. To navigate to another page, it is safest (for cross-browser and backward compatibility) to assign a URL string value to the location.href property, rather than this document-centered property. |
|
Example | |
document.URL = "http://www.megacorp.com"; |
|
Value | |
Complete or relative URL as a string. |
|
Default | |
The current document's URL. |
URLUnencoded | NN n/a IE 5.5(Win) DOM n/a |
|
Read-only |
Returns the URL of the current document, but with any URL-encoded characters returned to their plain-language version (e.g., %20 is converted to a space character). The returned value is the same as if applying the JavaScript decodeURI( ) function to document.URL. |
|
Example | |
var straightPath = document.URLUnencoded; |
|
Value | |
Complete or relative URL as a string. |
|
Default | |
The current document's URL. |
vlinkColor | NN 2 IE 3 DOM n/a |
|
Read/Write (IE) |
Color of a hypertext link that has been visited recently. The color is applied to the link text or border around an image or object embedded within an a element. See also alinkColor and linkColor properties for clicked and unvisited link colors. Changes to this property do not dynamically change the link color in Navigator 4 or earlier. Starting with IE 4 and Netscape 6, you should switch to using the W3C DOM alternative, document.body.vLink, or style sheets. |
|
Example | |
document.vlinkColor = "gold"; |
|
Value | |
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names. |
|
Default | |
#551a8b (Navigator); #800080 (Internet Explorer Windows); #006010 (Internet Explorer Macintosh). |
width | |
|
|
See height. |
addBinding( ), getAnonymousElementByAttribute( ), getAnonymousNodes( ), getBindingParent( ), loadBindingDocument( ), removeBinding( ) | NN 6 IE n/a DOM n/a |
|
|
This series of Netscape 6 document object methods are part of a browser programming feature called Extensible Binding Language (XBL), an adjunct to the XML-based mechanism that the browser uses for generating user interface skins. To learn more about XBL, visit http://www.mozilla.org/docs/xul/xulnotes/xulnote_xbl.html. |
captureEvents( ) | NN 4 IE n/a DOM n/a |
captureEvents(eventTypeList) |
|
Instructs the browser to grab events of a specific type before they reach their intended target objects. The object invoking this method must then have event handlers defined for the given event types to process the event. Although this method is part of the Navigator 4 event model, it continues to be supported in Netscape 6, creating the equivalent of a W3C DOM capture-mode event listener for the document object. Continue to use this method if you must support Navigator 4, but migrate new code to the W3C DOM event listener syntax as described in Chapter 6. |
|
Parameters | |
|
|
Returned Value | |
None. |
clear( ) | NN 2 IE 3 DOM n/a |
|
|
Removes the current document from the window or frame, usually in preparation to open a new stream for writing new content. The document.write( ) and document.writeln( ) methods automatically invoke this method. Many bugs with the document.clear( ) method plagued earlier browser versions. Even today, it is best to let the document writing methods handle the job for you. The W3C DOM explicitly omits this method. |
|
Parameters | |
None. |
|
Returned Value | |
None. |
close( ) | NN 2 IE 3 DOM 1 |
|
|
Closes the document writing stream to a window or frame. If a script uses document.write( ) or document.writeln( ) to generate all-new content for a window or frame, you must append a document.close( ) method to make sure the entire content is written to the document. Omitting this method may cause some content not to be written. This method also prepares the window or frame for a brand new set of content with the next document writing method. Do not, however, use document.close( ) if you use the document writing methods to dynamically write content to a page while loading from the server. |
|
Parameters | |
None. |
|
Returned Value | |
None. |
createAttribute( ) | NN 6 IE 5(Mac)/6(Win) DOM 1 |
createAttribute("attributeName") |
|
Generates in memory an instance of an attribute node (Attr object). A typical sequence is to create the attribute, assign a value to it via its nodeValue property, and then insert the Attr node into an element's attribute list via the element's setAttributeNode( ) method. |
|
Parameters | |
|
|
Returned Value | |
Attr node object reference. |
createAttributeNS( ) | NN 6 IE n/a DOM 2 |
createAttributeNS("namespaceURI", "qualifiedName") |
|
Generates in memory an instance of an attribute node (Attr object) whose name is defined in an external namespace. A typical sequence is to create the attribute, assign a value to it via its nodeValue property, and then insert the Attr node into an element's attribute list via the element's setAttributeNodeNS( ) method. |
|
Parameters | |
|
|
Returned Value | |
Attr node object reference. |
createCDATASection( ) | NN 6 IE 5(Mac) DOM 1 |
createCDATASection("data") |
|
Generates in memory an instance of a character data section node (CDATASection object) in an XML (including XHTML) document. Not fully implemented as of Netscape 7. |
|
Parameters | |
|
|
Returned Value | |
CDATASection node object reference. |
createComment( ) | NN 6 IE 5(Mac)/6(Win) DOM 1 |
createComment("commentText") |
|
Generates in memory an instance of a comment node (Comment object with a nodeValue of 8). A typical sequence is to create the Comment node, then insert it into the desired location of the document tree via any node's appendChild( ) or insertBefore( ) method. Only partially implemented in IE 5/Mac. |
|
Parameters | |
|
|
Returned Value | |
Comment node object reference. |
createDocumentFragment( ) | NN 6 IE 5(Mac)/6(Win) DOM 1 |
|
|
Generates in memory an instance of an empty document fragment node (DocumentFragment object). This node becomes an arbitrary holder for assembling a sequence of nodes that ultimately get appended or inserted into a document tree. See the DocumentFragment object for more details. |
|
Parameters | |
None. |
|
Returned Value | |
DocumentFragment node object reference. |
createElement( ) | NN 6 IE 4 DOM 1 |
createElement("tagName") |
|
Generates in memory an instance of an element object associated with the tag passed as a parameter to the method. The method is limited to area, img, and option elements in IE 4; all elements are permitted in other supporting browsers. A newly created element has no attribute values assigned (except any default values assigned according to the DTD), nor is the element yet part of the document tree. Assign attributes (such as the type for an input element or id for any element), and append or insert the element into the document tree. This sequence is the W3C DOM approach to generating new content (in place of the innerHTML convenience properties implemented in IE and Netscape 6 browsers). |
|
Parameters | |
|
|
Returned Value | |
Element object reference. |
createElementNS( ) | NN 6 IE n/a DOM 2 |
createElementNS("namespaceURI", "qualifiedName") |
|
Generates in memory an instance of an element object associated with namespace, label, and tag passed as parts of the method's parameters. A newly created element has no attribute values assigned (except any default values assigned according to the DTD), nor is the element yet part of the document tree. Assign attributes (such as the type for an input element or id for any element), and append or insert the element into the document tree. |
|
Parameters | |
|
|
Returned Value | |
Element object reference. |
createEntityReference( ) | NN 6 IE 5(Mac) DOM 1 |
createEntityReference("entityName") |
|
Generates in memory an instance of an entity reference node object in an XML document. Only partial support provided in IE 5/Mac and Netscape as of Version 7. |
|
Parameters | |
|
|
Returned Value | |
Entity reference node object reference. |
createEvent( ) | NN 6 IE n/a DOM 2 |
createEvent("eventType") |
|
Generates in memory an instance of a W3C DOM Event object of a particular event category. After the generic event is created, it must be initialized (via one of several initialization methods) as a particular event type, along with other properties appropriate for the event category. The following sequence creates a mousedown event and sends it to an element: var evt = document.createEvent("MouseEvents"); evt.initEvent("mousedown", true, true); document.getElementById("myElement").dispatchEvent(evt); |
|
Such an event might then be handed to an element (via the element's dispatchEvent( ) method) so that the element's event listener can process the event as if it had been generated by a user clicking the mouse button. |
|
Parameters | |
|
|
Returned Value | |
Event object object reference. |
createEventObject( ) | NN n/a IE 5.5(Win) DOM n/a |
createEventObject([existingEventObject]) |
|
Generates in memory an instance of an empty IE DOM event object. After the generic event is created, its properties can be stuffed with pertinent values to help the event be processed. Then the event acts as a parameter to an element's fireEvent( ) method, at which point the event type is associated with the event. The following sequence creates a mousedown event and sends it to an element: var evt = document.createEventObject( ); document.getElementById("myElement").fireEvent("onmousedown", evt); |
|
You can also use an existing event object as a model for a script-generated event. Pass the current event object as a parameter to the createEventObject( ) method, and modify the properties of the new object as you see fit. |
|
Parameters | |
|
|
Returned Value | |
event object reference. |
createNodeIterator( ) | NN n/a IE n/a DOM 2 | |||||||||||||||||
createNodeIterator(rootNode, whatToShow, filterFunction, entityRefExpansion) |
||||||||||||||||||
Generates in memory an instance of a NodeIterator object. This method has the same set of parameters as the createTreeWalker( ) method, which is implemented in Netscape 7. |
||||||||||||||||||
Parameters | ||||||||||||||||||
|
||||||||||||||||||
Returned Value | ||||||||||||||||||
NodeIterator object reference. |
createProcessingInstruction( ) | NN 6 IE 5(Mac) DOM 1 |
createProcessingInstruction("target", "data") |
|
Generates in memory an instance of a processing instruction node object in an XML document. Only partial support provided in IE 5/Mac and Netscape as of Version 7. |
|
Parameters | |
|
|
Returned Value | |
Processing instruction node object reference. |
createRange( ) | NN 6 IE n/a DOM 2 |
|
|
Creates a blank Range object, whose boundary points are collapsed to the point before the first character of the rendered body text. The method returns a reference to that Range object, which you then use to adjust its boundary points, invoke its methods, and so on. See the Range object for details of its language features. |
|
Parameters | |
None. |
|
Returned Value | |
W3C DOM Range object reference. |
createStyleSheet( ) | NN n/a IE 4 DOM n/a |
createStyleSheet(["url"[, index]]) |
|
This method performs the same actions in IE for Windows and Macintosh, but their returned values differ. Moreover, the specific actions in the document tree depend upon the parameters passed with the method. When no parameters are included, the method inserts a blank style element into the document tree. This style element, however, is not reflected in the document.styleSheets collection until you add one or more style rules to the object. But if you specify a URL to an external .css file as the first parameter, the method creates and inserts a link element into the document's head section, bringing the external style rules to life immediately. |
|
IE for Windows always returns a reference to a styleSheet object; IE for Macintosh returns a reference to the newly inserted element, which will be a style or link element, depending on the parameter makeup. The inserted style element reference is of little help for adding a rule because you can't reference the styleSheet object. For cross-operating-system compatibility, it's best to use this method only for external style sheets. |
|
Parameters | |
|
|
Returned Value | |
styleSheet object reference (Windows); style or link element object reference (IE 5 and later for Macintosh). |
createTextNode( ) | NN 6 IE 5 DOM 1 |
createTextNode("text") |
|
Generates in memory an instance of a text node (W3C DOM Text object) whose nodeValue consists of the untagged text content passed as a parameter. A newly created text node is not yet part of the document tree. Append or insert the node into the document tree or document fragment being assembled for later document insertion. This sequence is the W3C DOM approach to generating new content (in place of the innerText convenience property implemented in IE browsers). |
|
Parameters | |
|
|
Returned Value | |
Text node object reference. |
createTreeWalker( ) | NN 7 IE n/a DOM 2 | |||||||||||||||||
createTreeWalker(rootNode, whatToShow, filterFunction, entityRefExpansion) |
||||||||||||||||||
Generates in memory an instance of a TreeWalker object. |
||||||||||||||||||
Parameters | ||||||||||||||||||
|
||||||||||||||||||
Returned Value | ||||||||||||||||||
TreeWalker object reference. |
elementFromPoint( ) | NN n/a IE 4 DOM n/a |
elementFromPoint(x, y) |
|
Returns a reference to the object directly underneath the pixel coordinates specified by the x (horizontal) and y (vertical) parameters. For an element to be recognized, it must be capable of responding to mouse events. Also, if more than one element is positioned in the same location, the element with the highest zIndex value or, given equal zIndex values, the element that comes last in the source code order is the one returned. |
|
Parameters | |
|
|
Returned Value | |
Element object reference. |
execCommand( ) | NN n/a IE 4(Win) DOM n/a |
execCommand("commandName"[, UIFlag[, value]]) |
|
Available only in the Win32 platforms for IE, the execCommand( ) method executes the named command. Most commands require that a TextRange object be created first for an insertion point. See Appendix D for a list of commands. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true if command was successful; false if unsuccessful. |
getAnonymousElementByAttribute( ) | |
|
|
See addBinding( ). |
getAnonymousNodes( ) | |
|
|
See addBinding( ). |
getBindingParent( ) | |
|
|
See addBinding( ). |
getElementById( ) | NN 6 IE 5 DOM 1 |
getElementById("elementID") |
|
Returns a reference to an element node from the document tree whose id attribute value matches the parameter value. If there is no match, the method returns null. This method, although a chore to type while observing its case-sensitive name, is the gateway for scripts in W3C DOM-capable browsers to communicate with element objects. |
|
Parameters | |
|
|
Returned Value | |
Reference to element node object. |
getElementsByName( ) | NN 6 IE 5 DOM 1 |
getElementsByName("elementName") |
|
Returns an array of references to all element nodes from the document tree whose name attribute value matches the parameter value. If there is no match, the method returns null. When an element supports both the name and id attribute, IE for Windows includes an element in the returned array even if only the id attribute is set to the parameter value. IE for Macintosh and Netscape 6 match only elements that have name attributes explicitly set to the parameter value. |
|
Parameters | |
|
|
Returned Value | |
Array of references to element node object. |
getSelection( ) | NN 4 IE n/a DOM n/a |
|
|
In Navigator 4, this method captures the current text selection in the document. The method is deprecated in Netscape 6 in favor of the window.getSelection( ) method (which returns a sophisticated selection object, rather than just text). Invoking from the document object displays a warning in the JavaScript Console window, but does not throw a full-fledged exception. The IE equivalent is reading the selection property. |
|
Parameters | |
None. |
|
Returned Value | |
String. |
handleEvent[ ] | NN |4| IE n/a DOM n/a |
handleEvent(event) |
|
Instructs the document object to accept and process the Navigator 4-only event whose specifications are passed as the parameter to the method. The object must have an event handler for the event type to process the event. |
|
Parameters | |
|
|
Returned Value | |
None. |
hasFocus( ) | NN n/a IE 6 DOM n/a |
|
|
Returns Boolean true if the document or any element in the document has focus. A background process, such as a function invoked through setTimeout( ) can find out if the document's window is currently the front window on the Desktop. |
|
Parameters | |
None. |
|
Returned Value | |
Boolean value: true | false. |
importNode( ) | NN 6 IE n/a DOM 2 |
importNode(nodeReference, deepBoolean) |
|
Imports a node object from another loaded document into the current document, but not yet into the document tree. In many ways, importNode( ) works like cloneNode( ), but it assumes that the source node may exist in an entirely different document tree context (especially in an XML document). W3C DOM rules for this method govern what properties and attributes of the source node make the journey and what happens to them upon their arrival. For example, an Attr node loses its ownerElement (i.e., its value becomes null) when imported from an element in one document into a fragment-like state in the new documentuntil the attribute gets added to an element in the new document. Nodes of Document and DocumentType types are not importable. |
|
The importNode( ) method does not assume the responsibility of persistence between documents. That's where, for instance, a JavaScript variable comes into play. As with cloneNode( ), the importNode( ) method does not disturb the source node. |
|
Parameters | |
|
|
Returned Value | |
Reference to the imported copy of the node object. |
loadBindingDocument( ) | |
|
|
See addBinding( ). |
open( ) | NN 2 IE 3 DOM 1 |
open(["MIMEType"][, "replace"]) |
|
Opens the output stream for writing to the current window or frame. If document.clear( ) has not already been invoked, it is automatically invoked in response to the document.open( ) method. Early version bugs may lead you to use document.write( ) and document.writeln( ) to take care of this method more reliably for you. |
|
Parameters | |
|
|
Returned Value | |
None. |
queryCommandEnabled( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandEnabled("commandName") |
|
Specifies whether the command can be invoked in light of the current state of the document or selection. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true if enabled; false if not. |
queryCommandIndeterm( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandIndeterm("commandName") |
|
Specifies whether the command is in an indeterminate state. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true | false. |
queryCommandState( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandState("commandName") |
|
Determines the current state of the named command. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
true if the command has been completed; false if the command has not completed; null if the state cannot be accurately determined. |
queryCommandSupported( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandSupported("commandName") |
|
Determines whether the named command is supported by the document object. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
Boolean value: true | false. |
queryCommandText( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandText("commandName") |
|
Returns text associated with the command. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
String. |
queryCommandValue( ) | NN n/a IE 4(Win) DOM n/a |
queryCommandValue("commandName") |
|
Returns the value associated with the command, such as the name font of the selection. Available only in the Win32 platform for IE 4. |
|
Parameters | |
|
|
Returned Value | |
Depends on the command. |
recalc( ) | NN n/a IE 5(Win) DOM n/a |
recalc([allBoolean]) |
|
Forces the recalculation of expressions assigned to element attributes via the setExpression( ) method. Needed only when automatic recalculation isn't triggered by user action, but affected values might have changed. |
|
Parameters | |
|
|
Returned Value | |
None. |
releaseEvents( ) | NN 4 IE n/a DOM n/a |
releaseEvents(eventTypeList) |
|
The opposite of document.captureEvents( ), this method turns off event capture at the document level for one or more specific events named in the parameter list. In Netscape 6, it performs the same action as the W3C DOM removeEventListener( ) method on the document object. See Chapter 6. |
|
Parameters | |
|
|
Returned Value | |
None. |
removeBinding( ) | |
|
|
See addBinding( ). |
routeEvent( ) | NN 4 IE n/a DOM n/a |
routeEvent(event) |
|
Used inside an event handler function, this method directs Navigator 4 to let the event pass to its intended target object. The method does not cause an error in Netscape 6, but it does not perform any action. |
|
Parameters | |
|
|
Returned Value | |
None. |
write( ), writeln( ) | NN 2 IE 3 DOM n/a |
write("string1"[, ..."stringN"]) writeln("string1"[, ..."stringN"]) |
|
When invoked as the page loads, these methods can dynamically add content to the page. When invoked after the page has loaded, a single method invocation clears the current document, opens a new output stream, and writes the content to the window or frame. A document.close( ) method is required afterward. Because the first document.write( ) or document.writeln( ) method destroys the current document, do not use two or more writing statements to create a new document. Instead, load the content into one variable and pass that variable as the parameter to a single document.write( ) or document.writeln( ) method. |
|
Using document.write( ) for <script> tags is tricky in Navigator because it typically interprets the writing of the end script tag as meaning the end of the script doing the writing. You should have success, however, if you split the end script tag into string sections: document.write(<" + "/script>");" |
|
If you include the "hide script" comment trick, write it this way: document.write("//--" + >");" |
|
The difference between the two methods is that document.writeln( ) adds a carriage return to the source code it writes to the document. This is not reflected in the rendered content, but can make reading the dynamic source code easier in browser versions that support dynamic content source viewing (Navigator 4 does so as a wysiwyg: URL in the source view window). |
|
Parameters | |
|
|
Returned Value | |
None. |