Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a <INPUT type=button> behave like the browser BACK button

Event Handling

Making a <INPUT type=button> behave like the browser BACK button

by  jpbrassard  Posted    (Edited  )
This is one of the simpler things to do in JavaScript, but it's a good way of demonstrating how you can use the onclick event in various form elements to increase the functionality of your web page or application.

There are two ways to force the browser to go back to the previous page visited. These are detailed below.

history.go
[tt]<input type=button name=backButton id=backButton value="Back" onclick="javascript:history.go(-1)">[/tt]

history.back
[tt]<input type=button name=backButton id=backButton value="Back" onclick="javascript:history.back">[/tt]

Either one of those will act the same as the user clicking the back button on the browser. [tt]history.go[/tt] is a little more powerful, because you can jump back more than one entry in JavaScript's [tt]history[/tt] collection, but for most simple web pages, [tt]history.back[/tt] will work just fine.

More info can be found at http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/history.html. DevEdge is a pretty good general resource for JavaScript stuff.

HTH,
jp
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top