JavaScript Kit > JavaScript Reference > Here
Document Object
Document is the parent object of numerous other objects, such as "images", "forms" etc.
Properties
Properties | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
alinkColor | Specifies the color of activated links in the document (Alink attribute). | ||||||||
all[] | IE4+ exclusive array that contains all of the elements within the document. Use document.all["elementID"] or document.all.elementID to access an element. | ||||||||
anchors[] | An array containing all of the anchors in the document. | ||||||||
applets[] | An array containing all of the applets in the document. | ||||||||
bgColor | Specifies the background color of the document. | ||||||||
compatMode | Returns the compatibility mode of the current
document, specifically, whether the page is rendered in Quirks or
Stricts mode. The two possible values returned are "BackCompat " for
Quirks and "CSS1Compat " for Strict. Useful for determining the
doctype
setting of the page and executing different code accordingly.Example(s): if (document.compatMode=="CSS1Compat") |
||||||||
cookie | A string containing the name/value pair of cookies in the document. | ||||||||
document.documentMode IE8 only property |
IE8 property that detects the document mode used by
the browser to render the current page. Because IE8 can render a
page in various different modes depending on the page's doctype plus
the presence of certain HTML elements, documentMode
returns a different number depending on the mode the page is being
rendered in. They are
Microsoft recommends you use |
||||||||
domain | Specifies the domain name of the server that served a document. Used for security purposes. | ||||||||
embeds[] | An array containing all of the plug-ins in the document, represented using the <embed> tag. | ||||||||
fgColor | Specifies the default text color of the document (text attribute). | ||||||||
fileSize | Returns the file size of the current document. In IE Windows, a numeric string is returned, while in IE Mac, a number instead. IE only property. | ||||||||
forms[] | An array containing all of the forms on the page. | ||||||||
images[] | An array containing all of the images on the page. | ||||||||
lastModified | Specifies the last modified date of the document, as reported by the web server. | ||||||||
linkColor | Specifies the color of unvisited links in the document (link attribute). | ||||||||
links[] | An array containing all of the links on the page. | ||||||||
plugins[] | Same as embeds[] object. | ||||||||
readyState IE property. Supported in Opera 9+, Chrome, and FF 3.6+ as well. |
Returns the loading
status of the document. It returns one of the below 4 values:
Use the o document.onreadystatechange=function(){ |
||||||||
referrer | A string that specifies the URL in which the user derived from to reach the current, usually via a link. | ||||||||
title | Specifies the title of the document. Read/write in modern browsers. | ||||||||
URL | A string that specifies the complete URL of the document. | ||||||||
vlinkColor | Specifies the color of visited links in the document (vlink attribute). |
Methods
Note: "[]" surrounding a parameter below means the parameter is optional.
Methods | Description |
---|---|
close() | Closes a document stream opened using document.open(). |
getElementById("ID") | A cross browser (IE5/NS6+) DOM method for accessing any element on the page via its ID attribute. |
open([mineType]) | Opens a document stream in preparation for document.write() to write to it. Use the optional "mineType" argument (default is text/html) to specify a specific minetype, such as "image/gif." Example(s). |
write("string") | Writes to the document (as it's loading) or document stream the "string" entered. Example(s). |
writeln("string") | Writes to the document (as it's loading) or document stream the "string" entered and inserts a newline character at the end. |
Examples
open([mineType])
This example opens a blank window and writes to it:
win2=window.open("") //open blank window and write to it
win2.document.open() //open document stream
win2.document.write("<b>Some text</b>")
win2.document.close()
write("string")
Writes out the current document's URL while the page is loaded:
document.write("This page\'s URL is "+document.URL)
- JavaScript Operators
- JavaScript Statements
- Global functions
- JavaScript Events
- Escape Sequences
- Reserved Words