Moving Forward and Back

By David Wall, ITworld |  How-to

It seems logical; if you have access the history object's URLs, then
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
provides two methods -- history.forward() and history.back() -- to
perform exactly that function. You'll use those methods to create
navigation buttons in this exercise.


Forward and Back Buttons


Navigating with JavaScript Buttons




onClick="history.forward()">


With the following two lines of code, JavaScript attaches history
methods to buttons:


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.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question