It seems logical that if you have access to the URLs in the history
object, you should be able to make any of the documents represented by
the URLs appear in any window or frame. Indeed, you can. The history
object has two methods -- history.forward() and history.back() -- that
do exactly that. You'll use those methods to create navigation buttons
in this exercise.
<HEAD>
<TITLE>Forward and Back Buttons</TITLE>
</HEAD>
<BODY>
<H1>Navigating with JavaScript Buttons</H1>
<FORM>
<P><INPUT TYPE=BUTTON VALUE="Back" NAME="Back"
onClick="history.back()">
<P><INPUT TYPE=BUTTON VALUE="Forward" NAME="Forward"
onClick="history.forward()">
</FORM>
</BODY>
With the following two lines of code, JavaScript attaches history
methods to buttons:
<P><INPUT TYPE=BUTTON VALUE="Back" NAME="Back"
onClick="history.back()">
<P><INPUT TYPE=BUTTON VALUE="Forward" NAME="Forward"
onClick="history.forward()">
When clicked, the button defined by the top line sends the user back a
step in his or her History list. The bottom line does the opposite,
sending the user forward a step, if possible. You can't see what the
pages ahead and behind are, but you can send the browser to them.
The History object also has a third method: go(). You can use the go()
method to move the browser forward or back a certain number of steps in
the History list, like this:
history.go(3);
history.go(-2);
For the go() method, positive numbers represent moves forward in the
list; negative numbers represent backward moves. A call to go(0) is a
reload of the current page.