ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Moving Forward and Back
JAVASCRIPT --- 09/03/2002

David Wall

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. 

On this topic

<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.

 

David Wall works as a freelance writer, programmer, lecturer, and consultant. Based near Washington, D.C., David has written and co- written several books, including Graphics Programming with JFC. David can be reached at David.Wall@itworld.com.



Advertisements
Sponsored links
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Newsletters  JAVASCRIPT
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   Industry Standard   Infoworld   ITworld  
JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

DEMO   IDG Connect   IDG Knowledge Hub   IDG TechNetwork   IDG World Expo  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.