How to emulate back button using javascript

Possible duplicate:
Page History - Does the back button exist?

I need to have a link on some pages of the website, clicking on it, it should return to the previous page, like a browser return button. What is the right way to do this? I think I should use some client side scripts such as Javascript, right?

+8
javascript html hyperlink
source share
7 answers

In JavaScript, this is:

history.go(-1); 

or

 history.back(); 
+23
source share

Just use

 history.go(-1); 

But after that, you will no longer be able to go forward (so the "Forward" button does not return you to where you were - that is, it is not 100% the same as when you click the "Back" button).

+7
source share

You can use:

 <form> <input type="button" value="ZurΓΌck" name="back" onClick="javascript:history.back(1)"> </form> 

Or within the link:

 <a href="javascript:history.back(1)">back</a> 

If you want to go forward, use history.forward(1) , but keep in mind: this only works if you called back() before!

+6
source share

Something like:

 <script> function goBack() { window.history.back() } </script> 

must do it.

+2
source share

Pressing the button brings the browser back

 <INPUT TYPE="BUTTON" VALUE="Go Back" ONCLICK="history.back()"> 
+2
source share

I think you can use the history API for browsers.

 window.history.back() 

That should work.

+1
source share
 <FORM><INPUT TYPE="BUTTON" VALUE="Go Back" ONCLICK="history.go(-1)"></FORM> 

Try this code

+1
source share

All Articles