An object that resides below the window in the scripting object model. A document may contain:
- Link - an array of hyperlinks found on the given document
- Anchor - an array of anchors found on the given document
- Form - an array of forms found on the given document
![]()
The document object reflects the HTML document currently in the browser and objects on the page--that is, links, forms, buttons, and ActiveX Objects. Methods and properties of the document object must be called in a script by placing document first in the statement. This means that if you wanted to set the background color on the page, the script would look like:
<script language="VBScript"> document.bgColor = "Blue" </script>The document object currently has no events.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Gets or sets the current color of the links in a document.
document.linkColor [=rgb-value|string]
Part Description document An object expression that evaluates to a document object. rgb-value Optional. The new color of links in the document. string Optional. A string value specifying the color.
Returns the rgb value of the current link color.
Note that this property can only be set at parse time, not after the page is painted. So the code:
<SCRIPT LANGUAGE="JavaScript"> document.vLinkColor = "green"; document.linkColor = "red"; document.alinkColor = "aqua"; </SCRIPT>sets the link color, while the code:
<FORM> "document.linkColor='#000000'"> <INPUT TYPE="button" VALUE="Set Visited Link Color to White" onClick = "document.vLinkColor='#FFFFFF'"> </FORM>will have no effect when the button is clicked. The performance hit of changing the link color after parse time is simply too great.
aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Gets or sets the current color of the active links in a document. A link is active when the mouse pointer is held down over the link but not released. Note that Internet Explorer does not have this feature, so aLinkColor has no effect; however, it is supported in the object model for compatibility reasons. As with linkColor, this property can only be set at parse time. For details, see the examples in linkColor.
document.aLinkColor [=rgb-value|string]
Part Description document An object expression that evaluates to a document object. rgb-value Optional. The new color of links in the document. string Optional. A string value specifying the color.
Returns the rgb value of the current link color.
linkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Gets or sets the current color of the visited links in a document. As with linkColor, this property can only be set at parse time. See the examples in linkColor for details.
document.vLinkColor [=rgb-value|string]
Part Description document An object expression that evaluates to a document object. rgb-value Optional. The new color of links in the document. string Optional. A string value specifying the color.
Returns the rgb value of the current link color.
linkColor, aLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Gets or sets the current color of the background in a document.
document.bgColor [=rgb-value|string]
Part Description document An object expression that evaluates to a document object. rgb-value Optional. The new color of the background in the document. string Optional. A string value specifying the color.
Returns the rgb value of the current background color.
To set the background color to white, use:
document.bgColor="000000"
linkColor, aLinkColor, vLinkColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Gets or sets the foreground color.
document.fgColor[=rgb-value]
Part Description document An object expression that evaluates to a document object. rgb-value Optional. The new color of the foreground in the document.
To set the foreground color to white, use:
document.fgColor="000000".
linkColor, aLinkColor, vLinkColor, bgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Returns the array of anchors in a document.
document.anchors[integer]
Part Description document An object expression that evaluates to a document object.
Returns an object expression that evaluates to the array of anchors.
To access the first anchor in the document, use:
document.anchors[0]To get the length of the anchors array, use:
document.anchors.length
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, links, forms, location, lastModified, title, cookie, referrer
Returns the array of links for the current document.
document.links [integer]
Part Description document An object expression that evaluates to a document object.
Returns an object expression that evaluates to the array of links.
To access the first link in the document, use:
document.Links[0]To get the length of the links array, use:
document.links.lengthNote that the locations in the links collection are read-only in the current build. In future builds you will be able to reset the targets of links.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, forms, location, lastModified, title, cookie, referrer
Returns the array of forms in a document.
document.forms [integer]
Part Description document An object expression that evaluates to a document object.
Returns an object expression that evaluates to the array of forms.
To access the first form in the document, use:
document.Forms[0]To get the length of the forms array, use:
document.forms.length
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, location, lastModified, title, cookie, referrer
Returns a read-only representation of the location object.
document.location
Part Description document An object expression that evaluates to a document object.
Returns an object expression that evaluates to the location object of the document.
To set String1 to the document's URL, use:
String1 = document.location.Href
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, lastModified, title, cookie, referrer
Returns the last modified date of the current page.
document.lastModified
Part Description document An object expression that evaluates to a document object.
Returns a string containing the date.
To set Date1 to the document's URL, use:
Date1 = document.lastModified
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, title, cookie, referrer
Returns a read-only representation of the document's title.
document.title
Part Description document An object expression that evaluates to a document object.
Returns an object expression that evaluates to the location object of the document.
To set String1 to the document's title, use:
String1 = document.title
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, cookie, referrer
Gets or sets the cookie for the current document.
document.cookie [=newcookie]
Part Description document An object expression that evaluates to a document object. newcookie Optional. The new value for the cookie. Because the cookie file is just a text file, this value is a string.
Returns a string containing the current cookie.
The cookie is a string expression stored for the current page. Note that setting the cookie overwrites any current cookie information. Also note that you can use string expressions to locate particular information in the cookie string.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, referrer
Gets the URL of the referring document.
document.referrer
Part Description document An object expression that evaluates to a document object.
Returns a string containing the URL of the referring document.
Currently returns the URL of the referring document when there is a referrer, and NULL when there is no referrer.
The referring document is the document that contained the link the user clicked on to get to the current document. For example, if the user is on www.microsoft.com and clicks on a link to navigate to www.msn.com, the referrer property of the document for www.msn.com is www.microsoft.com. Note that by definition the referrer varies depending on how the user linked to the current document. If the user navigated to the document without clicking on a link from another page, referrer should return NULL.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie
Places the given string into the current document. Unless otherwise specified, the string is appended to the current document at the current position.
document.writestring
Part Description document An object expression that evaluates to a document object. string The string to write to the current document. Note that the string is added into the HTML directly, so it must be formatted as HTML.
The following examples demonstrate the use of the write method:
<HTML><BODY> <SCRIPT LANGUAGE='VBS'> document.Write ("Hello world.") </SCRIPT> This is a document. </BODY></HTML>results in:
Hello world. This is a document.Whereas:
<HTML><BODY> This is a document. <SCRIPT LANGUAGE='VBS'> document.Write ("Hello world.") </SCRIPT> </BODY></HTML>results in:
This is a document. Hello world.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Places the given string into the current document with a new-line character appended to the end.
document.writeLn string
Part Description document An object expression that evaluates to a document object. string The string to write to the current document. Note that the string is added into the HTML directly, so it must be formatted as HTML.
This method is the same as the document.write method with the addition of a newline character at the end. Note that a newline is ignored by HTML unless it is bracketed by <PRE> tags, so in many cases document.write and document.writeLn behave exactly the same.
The following examples demonstrate the use of the writeLn method:
<SCRIPT LANGUAGE='VBS'> document.writeLn ("Hello world.") document.write ("Hello world.") </SCRIPT>results in:
Hello world. Hello world.Whereas:
<PRE> <SCRIPT LANGUAGE='VBS'> document.writeLn ("Hello world.") document.write ("Hello world.") </SCRIPT> </PRE>results in:
Hello world. Hello world.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Opens the document stream for output.
document.open [mimeType]
Part Description document An object expression that evaluates to a document object. mimeType Optional. A string containing a valid mime type. Note that this can include types supported by Internet Explorer (text/html, text/plain), but can also include other types (application/x-director for MacroMedia director). In the case of other types, Internet Explorer creates a file containing the data between document.open and document.close calls, and hands the created file to the correct application.
This method is implemented in the current build; however, the mime-type is currently ignored (html is always assumed).
Generally document.open is followed by a sequence of document.write or document.writeLn statements, followed by document.close. If the referenced document exists already, any information contained in the document is cleared. To write "Hello World" to the document, use:
document.open document.writeLn "Hello World" document.closeNote that this is identical to:
document.writeLn "Hello World"with two exceptions.
- In the first example, "Hello World" is written to the screen after document.close; in the second, it is written immediately.
- In the first example, document.open clears the document if there is data; in the second, "Hello world" is appended to the end.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Updates the screen to display all of the strings written after the last open method call.
document.close
Part Description document An object expression that evaluates to a document object.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer
Closes the document output stream and writes the data to the screen. See the open method description for more information and examples.
document.clear
Part Description document An object expression that evaluates to a document object.
Not implemented in current build.
linkColor, aLinkColor, vLinkColor, bgColor, fgColor, anchors, links, forms, location, lastModified, title, cookie, referrer