The History Object
The
history
property of the Window object refers
to a History object for the window. The History object was originally
designed to model the browsing history of a window as an array of
recently visited URLs. This turned out to be a poor design choice,
however; for important
security and privacy reasons, it is almost
never appropriate to give a script access to the list of web sites
that the user has previously visited. Thus, the array elements of the
History object are never actually accessible to scripts (except when
the user has granted permission to a signed script in Netscape 4 and
later). The length
property of the History object is accessible, but it does not provide
any useful information.
Although its array elements are inaccessible, the History object
supports three methods (which can be used by normal, unsigned scripts
in all browser versions). The
back( )
and
forward( )
methods
move backward or forward in a window’s (or frame’s)
browsing history, replacing the currently displayed document with a
previously viewed one. This is similar to what happens when the user
clicks on the Back and Forward browser buttons. The third method,
go( )
, takes an integer
argument and can skip forward or backward in the history list by
multiple pages.
Unfortunately,
go( )
suffers from
bugs in Netscape 2 and 3 and has incompatible behavior in Internet
Explorer 3; it is best avoided prior to fourth-generation browsers.
Example 13-6 shows how you might use the ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.