Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


The history.length, therefore, would return the number of entries in the history list. The methods history.back() and history.forward() would cause the Web browser to load the previous and next entry in the history list, if any.

Table 19.2 The history Object Contains Information on the Browser’s History List

Property Type What It Does

current property contains the URL of the current history entry
length property contains the number of entries in the history list
previous property contains the URL of the previous history stack entry
next property contains the URL of the next history stack entry
back() method goes back one entry in the history list
forward() method goes forward one entry in the history list
go(num) method goes forward num entries in the history stack if num > 0,
otherwise it goes backward -num entries
go(string) method goes to the newest history entry whose title or URL contains
string as a substring; the string case doesn’t matter

The document Object

Web browsers also expose an object called document. As you might expect, this object exposes useful properties and methods of the active document. The location object refers only to the URL of the active document, but document refers to the document itself. Chapter 20 discusses the document object in more detail, but its basic properties and methods are shown here.

  See “Filling Your Windows II: The document Object,” p. 496.

document Object Properties

You can access and manipulate a number of attributes of the current Web browser document through the document object. Some of the more useful document object properties are the following:

  alinkColor—The color of the document’s active link
  bgColor—The background color of the document
  cookie—The document’s cookie
  domain—Domain name of the server that served the document
  fgColor—The foreground color of the document
  lastModified—The date the document was last modified
  linkColor—The color of the document’s links
  referrer—The URL of the document from which this document was called
  title—The contents of the <TITLE> tag
  URL—The complete URL of the document
  vlinkColor—The color of the document’s visited links

In addition to the properties in the preceding list, remember that the anchor, link, form, and image objects are also properties of the document object.

document Object Methods

You can use JavaScript to operate on documents by using the methods associated with the document object. The following are some of these methods:

  close()—Closes the specified document.
  eval(string)—Evaluates string as JavaScript code and returns the result.
  open()—Opens a stream for a new document. This document is meant to be filled with the output of calls to the document.write() and/or document.writeln() methods.
  write(expression, [expression…])—Writes one or more HTML expressions.
  writeln(expression, [expression…])—Identical to write(), except this method appends a newline.

Listing 19.2 shows a JavaScript that accesses and displays some of the properties of the document object. Notice that the link object is accessed through the links array, one for each URL link on the current Web page (see the “JavaScript Object Arrays” section later in this chapter). Figure 19.4 shows the results of loading this Web page.

Listing 19.2 Document.htm—The document Object Enables You to Access and Set Information About the Current Document


<HTML>
<HEAD>
<TITLE>The Document Object</TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<A HREF=“<http://www.rpi.edu/~odonnj/>”>JOD’s Home Page</A>
<A HREF=“<http://www.rpi.edu/~odonnj/que/Window.htm>”>The Window Object</A>
<A HREF=“<http://www.rpi.edu/~odonnj/que/Location.htm>”>The Location Object</A>
<A HREF=“<http://www.rpi.edu/~odonnj/que/Document.htm>”>The Document Object</A>
<HR>
<A HREF=“mailto:odonnj@rpi.edu”>Jim O’Donnell</A>
<HR>
<SCRIPT LANGUAGE=“JavaScript”>
<!-- Hide this script from incompatible Web browsers! -->
var n
document.writeln(“Current document information:<PRE>”)
document.writeln(“<UL>”);
document.writeln(“<LI>document.title      =”,document.title)
document.writeln(“<LI>document.location    =”,document.location)
document.writeln(“<LI>document.lastModified=”,document.lastModified)
for (n=0;n < document.links.length;n++)
   document.writeln(“<LI>document.links[“,n,”].href=”,
      document.links[n].href)
document.writeln(“<LI>document.linkColor   =”,document.linkColor)
document.writeln(“<LI>document.alinkColor  =”,document.alinkColor)
document.writeln(“<LI>document.vlinkColor  =”,document.vlinkColor)
document.writeln(“<LI>document.bgColor     =”,document.bgColor)
document.writeln(“<LI>document.fgColor     =”,document.fgColor,”<PRE><BR>”)
document.writeln(“</UL>”);
//  Hide this script from incompatible Web browsers! -->
</SCRIPT>
</BODY>
</HTML>


FIGURE 19.4  document object properties contain information about the current document displayed in the Web browser.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.