|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
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.
The document ObjectWeb 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.
document Object PropertiesYou 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:
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 MethodsYou can use JavaScript to operate on documents by using the methods associated with the document object. The following are some of these methods:
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.htmThe 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/>>JODs 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 ODonnell</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>
|
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. |