How can I go to history.back () when the page loads?

I have a PHP page that has an error, but if I return, everything will be fine. I cannot redirect because the page can be accessed from two different places.

How can I create javascript that loads automatically when the page loads?

Thanks Sebastian

EDIT

that won't work. is there any way to get the url of history.go (-2)?

thanks Sebastian

+4
source share
3 answers
... <body onload="history.go(-1);"> ... 
+2
source

The problem with using the onload onload property is that you do not want the user to wait for the current page to load. Just place this code / HTML at the top of the page immediately after opening the <head> .

 <script type="text/javascript">history.go(-1);</script> 
+1
source

You can use the window.history object , for example:

 history.back(); //or: history.go(-1); 
0
source

All Articles