I have a PHP page that has an error, but if I go back, it works fine. I can't redirect because the page can be accessed from two different places.
How can I make a JavaScript that loads automatically when the page loads?
Thanks, Sebastian
EDIT
that wouldn't work. is there a way to get the url of history.go(-2)?
thanks, Sebastian
I have a PHP page that has an error, but if I go back, it works fine. I can't redirect because the page can be accessed from two different places.
How can I make a JavaScript that loads automatically when the page loads?
Thanks, Sebastian
EDIT
that wouldn't work. is there a way to get the url of history.go(-2)?
thanks, Sebastian
Share Improve this question edited Oct 25, 2010 at 12:47 sebastian asked Oct 25, 2010 at 11:31 sebastiansebastian 1,5548 gold badges26 silver badges39 bronze badges 1- 3 I don't really understand. Wouldn't it be more sensible to fix the error in the first place? – Pekka Commented Oct 25, 2010 at 11:33
3 Answers
Reset to default 2...
<body onload="history.go(-1);">
...
The problem with using the window's onload property is that you do not want the user to wait for the current page to load. Just put this code/HTML at the top of the page right after the opening <head>
tag.
<script type="text/javascript">history.go(-1);</script>
You can use the window.history
object, like this:
history.back();
//or:
history.go(-1);