Go Back to Previous Page
You can use a link to invoke
<a href="<?= $previous ?>">Back</a>
HTTP_REFERER variable sometimes not work.
Read more... Read less...
Depends what it is that you're trying to do it with. You could use something like this:
That's the simplest option. The other poster is right about having a proper flow of history but this is an example for you.
Just edited, orig version wasn't indented and looked like nothing. ;)
You specifically asked for JS solutions, but in the event that someone visits your form with JS disabled a PHP backup is always nice:
when the form loads grab the previous page address via something like
$previous = $_SERVER['HTTP_REFERER']; and then set that as a
<input type="hidden" value="$previous" /> in your form. When you process your form with the script you can grab that value and stick it in the
header("Location:___") or stick the address directly into a link to send them back where they came from
No JS, pretty simple, and you can structure it so that it's only handled if the client doesn't have JS enabled.
Here is the code of this button
<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);">
However, if the server just returns new content without redirecting - then history.go(-1) is not going to help you. At that point you have lost your form.
If you just want to simply go back to the previous url - just link to it with an A HREF tag. That will show you an empty form.