Code Snippet
“Go Back” Button
Browsers already have "back" buttons, so you'd better have a darn good reason for needing to put one on your page!
Input button with inline JavaScript
<input type="button" value="Go Back From Whence You Came!" onclick="history.back(-1)" />This is totally obtrusive, but you could fix that by only appending this button through JavaScript.
PHP
If JavaScript isn't a possibility, you could use the HTTP_REFERER, sanitize it, and echo it out via PHP.
<?php
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "<a href='$url'>back</a>";
?>
1. Many users aren’t aware of their browser back button.
2. Users filling forms often make errors. Therefore, they complete the form, it goes through edit checks on the server, then it displays their input and asks if it is correct. If not, they need to return to correct it. A return button, front-and-center, becomes applicable.
3. The browser back button and the scripted back button do not always behave in the same manner. If you’re looking for a specific behavior, then, it needs to be created.
Oh. The javascript:history.go(-1) and its derivatives returns an Expired Page in IE8
simple HREF=”javascript:history.go(-1)”>Back
Just wanna say thanks for the ‘Back’ button/link… working perfectly :) I used the one in php with one of my projects.
Thanks a bunch!
hey
thanks for php version, it works great.
may be you can help me in customize it… i need conditional construct with check about count of previous pages. i want to hide this button if user looks his first page. sometimes it’s not the main page.
tia.
Been looking for this for ages, thanks . Will come in very useful at the bottom of an article ,but is there a way to change the button for a image.
David if you really need to ask that i’m not sure your in the right place, but here you are bud,
Good luck!
the php code works, but there’s an issue and I need some help fixing it.
Example:
I go to page A
then I go to Page B, and click to go to Page C,
When I click the back button on Page C, I get to Page B.
When I click the back button on Page B, I get to Page C.
How can I fix this?
I love this button its had great use on my site, thank you for taking your time to share :).
Other than what was said in the first post, is there any reason for it to be like that?