Main Page

document object

Although it’s not possible to see the URLs in the browser history, you can see how many pages are in it
by using the
length
property:
alert(“There are currently “ + history.length + “ pages in history.”);
This capability is helpful if you want to go back or forward by more than one page and want to know if
that is possible.
The document object
The
document
object is actually a property of the
window
object, but as you learned earlier, any property
or method of the window object may be accessed directly, so this line of code will return
“true”
:
alert(window.document == document);
It is also unique in that it is the only object that belongs to both the BOM and the DOM (the
document
as
it relates to the DOM is discussed in the next chapter). From the BOM perspective, the
document
object
is made up of a series of collections that access various parts of the document as well as give information
about the page itself. Once again, because the BOM has no standards guiding implementations, each
browser tends to have slightly different implementations for
document
; this section focuses on the most
common functionality.
The following table lists some of the common properties for the BOM
document
object:
Property
Description
alinkColor
The color for active links as defined by
<body alink=”color”>
*
bgColor
The color for the page background as defined by
<body
bgcolor=”color”>
*
fgColor
The color for text as defined by
<body text=”color”>
*
lastModified
The date the page was last modified as a string
linkColor
The color for links as defined by
<body link=”color”>
*
referrer
The URL one position back in the browser history
title
The text displayed in the
<title/>
tag
URL
The URL of the currently loaded page
vlinkColor
The color for visited links as defined by
<body vlink=”color”>
*
*These properties are deprecated because they refer to old HTML attributes of the
<body/>
tag. Style sheet
scripting should be used instead.
The
lastModified
property retrieves a string representing the date that the page was last modified,
which is of marginal use unless you want to display the last modified date on a home page (which can
also be done using server-side technology). Likewise, the
referrer
property isn’t very useful unless
149
JavaScript in the Browser
08_579088 ch05.qxd 3/28/05 11:37 AM Page 149


JavaScript EditorFree JavaScript Editor     Ajax Editor


©