Non-Object Document Properties

Besides the object-based properties, i.e. the Location object and the Anchor, Link, and Form collections (which will be covered in a moment), the Document object has a number of other properties that we might find useful in our client-side programming. We’ll briefly outline these properties next.

The Color Properties

As is fitting for an object that represents the current HTML page, there are a number of Document object properties that represent the color scheme of the current page. All of these properties return a seven character string when queried, in this form: #RRGGBB, where the R, G, and B values represent the current color setting for red, green, and blue, in hexadecimal.

Property Description
linkColor Color of non-visited links in the current document
vLinkColor Color of visited links in the current document
aLinkColor Color of active (clicked on but not visited) links.
fgColor The current foreground color
bgColor The current background color

These properties are set to read-only after the page has been parsed and displayed, so they can’t be changed in response to button clicks or other external input. They can, however, be set in script blocks – just make sure the code is parsed when the page is loaded, like it is with Write and WriteLn.

The Title Property

The Title property simply returns the current title of the document. The value of this property is whatever the HTML author placed between the <TITLE> and </TITLE> tags. This property is set to read-only after the page has loaded.

The Cookie Property

Cookie is a very useful read and write property, and can be used in conjunction with ASP’s Response.Cookies collection. This property returns or sets the cookie associated with the current page. Reading the Document.Cookie property returns the keys and values of the current page’s cookie, but doesn’t give other information. While this information isn’t returned when querying the property, we can set such things as expiration date and path when setting a cookie using client-side code.

To read the cookie into a variable named MyVar, we use the following code:

MyVar = Document.Cookie

After reading the value we can use the string-manipulation capabilities of our scripting language to find the part of the cookie we’re interested in.

To set the value of a key named MyKey to MyValue, we use this code. If MyKey already exists, its value will be replaced with the contents of MyValue:

Document.Cookie = "MyKey=MyValue"

Finally, if we’d like to set the path or other properties, like the expiration date, we just append them to the end of the key/value string, like this:

Document.Cookie = "MyKey=MyValue;expires=Monday, 01-Jan-98 12:00:00 GMT"

Cookies can also be used solely on the client-side to exchange information between pages. On the server we’re used to using the Session object to remember information from page to page, and script to script. There isn’t a handy object like this on the client, but simply by setting the cookie property of the document with a key/value pair that holds our variable name and its value, we can remember the contents of variables across pages. This method doesn’t work with object references, only with text and numerical values, but it can still be very useful. Microsoft’s VBScript site has a sample that shows the code needed to add this functionality to our pages.

The LastModified Property

This read-only property returns the date that the current document was last modified. Note that this property is only up to date as far as the most recently retrieved copy of the document—which may be older than the last modified version if our browser caches any pages (as most do).

The Referrer Property

On paper, the Referrer property returns the URL of the document that contained the link to the current page. In the real world, this is less than true. Internet Explorer 3.0’s Referrer property always returns the URL of the current page.

© 1997 by Wrox Press. All rights reserved.