Wednesday, October 04, 2006

JavaScript Back Button or Link

How do I make a back button or link?

This is a pretty common (and basic) question with an easy solution. Note that it requires you visitor have JavaScript enabled, but that covers about 96% or more of web surfers.

Link methods:
<a href="javascript:history.go(-1);">back</a>
<a href="#" onClick="javascript:history.go(-1);">back</a>
<a href="javascript:;" onClick="javascript:history.go(-1)">back</a>
Button method:
<input type="button" value="Go Back" onClick="javascript:history.go(-1);">
<img src="GoBackImage.jpg" onClick="javascript:history.go(-1);">
You can change how many pages you sent the use back by changing the value in the parentheses; (-2) will send them back 2 pages.

No comments: