Document Object


The document is the next important (after window) object in the hierarchy of Internet Explorer. It represents the HTML page displayed on the browser's window or one of its frames. You have already used the document object applying the document.write method to write strings on the current document. This method enables you to create documents on the fly. You  use this object most often in programming your Web pages, and this section discusses its properties and methods in detail. The scripting for it is as follows:

Document.PropertyName 'to refer to Document property

Document.MethodName [list of arguments] 'to refer to Document method

For example, the following code is used to set the background color of the document to red:

Document.bgColor=Red

The document Object's Properties

anchor

anchor is a property of the document object, and like some other properties, it's an object. The length property of the anchor object returns the number of anchors in the document. The individual anchors are stored in the anchors array, whose elements can be accessed with an index. anchors(0) is the name of the first anchor in the document (its value is the NAME attribute of the <A> tag that inserted the anchor in the document), anchors(1) is the second anchor, and so on.

link

The link property functions similarly to the anchor property, but instead of the anchors, it represents the hyperlinks in the current document. Like the anchors array, the links array is a property of the document, which represents the only object that may contain links.

lastModified

Returns the date the current document was last modified. You can use the lastModified property of the document object to display the date and time it was last modified, without having to hard-code this information in the document itself.

title

The title property returns the current document's title. This property is read-only and won't allow you to change the document's title at runtime.

referrer

Returns the URL of the referring document.

Color Properties

linkColor returns or sets the color of the hyperlinks in the document. This property is equivalent to the LINK attribute of the <BODY> tag. You assign the hexadecimal value of a color, or a color name, to the linkColor property:

document.linkColor="red"
document.linkColor="#FF0000"

Both statements set the color of the hyperlinks in the current document to red. The syntax of all other color properties is the same.

aLinkColor property returns or sets the color of the active link in the document. The active link represents the link which is under the mouse pointer as the mouse button is pressed and not released.

The copyright of the article Document Object in VB Script is owned by Maxim Karetnikov. Permission to republish Document Object in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic