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?
I reach a page with an update form on it which uses Dreamweavers PHP/MySQL Update Record function. I come to this from vatious source pages and want to go back to the page that sent me there once I hit the submit button. Given all the PHP code it is not a simple matter of chaning or creating a button with a link on it.
Any ideas on having the submit button go back to whatever page send it there in the first place?
I’ve got a new BibleRhymes site in the final stages of creation and I think your JS code will be a part of it. Thank youu!
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.