JavaScript Kit > JavaScript Reference > Here

Document Object

Last updated: September 13th, 2009

Document is the parent object of numerous other objects, such as "images", "forms" etc.


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.


if (document.compatMode=="CSS1Compat")
// execute code for page with a valid doctype

cookie A string containing the name/value pair of cookies in the document.

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
5 Page is running in IE5 mode (aka "quirks mode").
7 Page is running in IE7 standards mode.
8 Page is running in IE8 standards mode.

Microsoft recommends you use documentMode over compatMode to detect a webpage's doctype. See Defining Document Compatibility for more info.

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.

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:
uninitialized The document hasn't started loading yet.
loading The document is loading.
interactive The document has loaded enough whereby user can interact with it.
complete The document has fully loaded.

Use the onreadystatechange event handler to react whenever the readyState of the document changes. For example:

 if (document.readyState=="complete"){
  alert("Document loaded fully!")

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).


Note: "[]" surrounding a parameter below means the parameter is optional.

Methods Description
close() Closes a document stream opened using
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.



This example opens a blank window and writes to it:"") //open blank window and write to it //open document stream
win2.document.write("<b>Some text</b>")


Writes out the current document's URL while the page is loaded:

document.write("This page\'s URL is "+document.URL)

Reference List

Right column

CopyRight (c) 2018 JavaScript Kit. NO PART may be reproduced without author's permission. Contact Info