Reputation:
Is there a way for a page to go back a page onload using javascript or php?
Upvotes: 3
Views: 8724
Reputation: 109
Sometimes Safari in iOS ignores history.go(-1).
So I prefer to use the window.history.back() method:
<body onload="window.history.back()">
You can also delay the back operation to show a temporary message in the html body:
<body onload="setTimeout(function() { window.history.back(); }, 1000)">
Upvotes: 1
Reputation: 74
well another solution is:
<body onload='history.go(-1);'>
Upvotes: 0
Reputation: 25165
PHP is server side, so no. The page will get to the client and, when it reaches the client, the browser has to be instructed to go back.
That said you have two options. Javascript or HTML Meta Tags.
Javascript mootools example would be something like this:
window.addEvent('domready', function() {
history.go(-1);
});
You can also send it in HTML Meta Tags
<meta http-equiv="refresh" content="2;url=http://example.net">
Hope it helps! Be aware that this behavior is, generally, confusing to the user and should be used with caution.
Upvotes: 4
Reputation: 15944
Yes, use history.go(-1)
in Javascript.
For bonus points, ensure that there is actually a page to go back to before calling it, like this question suggests.
Upvotes: 4