The Back Button

So you would like to put a link on your page that will take visitor's back to the previous page that they were on. One that works just like the browser back button. Can you do it?

Yes, you can. Here is a button that does just that. Whatever page that you were on prior to coming to this page, the following button (just like the browser back button) will return you to it.

The code to produce this button is extremely simple.

 <form><input type="button" value=" <-- BACK " onclick="history.go(-1);return false;" /></form> 

That's all there is to it, the browser stores the list of all of the pages that you have visited in its history and the "history.go(-1)" tells the browser that you want the -1 entry from the history which corresponds to the previous page.

You can also create a link to the previous page without the button if you prefer.

Like this BACK.

The code to produce this link is also simple.

 <a href="#" onclick="history.go(-1);return false;">BACK</a> 

You can also modify the button or link to take you forward (like the browser forward button) using "history.go(1)" or to go back more than one page by using -2, -3, or whatever.

Note that the back button/link requires Javascript enabled in order to function. Your visitor will remain on the same page if their browser does not have Javascript enabled.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow