Friday, June 21, 2013

“Go Back” Button

  1. Browsers already have "back" buttons, so you'd better have a darn good reason for needing to put one on your page!
  2.  
  3. Input button with inline JavaScript
  4. <input type="button" value="Go Back From Whence You Came!" onclick="history.back(-1)" />
  5.  
  6. This is totally obtrusive, but you could fix that by only appending this button through JavaScript.
  7.  
  8. PHP
  9.  
  10. If JavaScript isn't a possibility, you could use the HTTP_REFERER, sanitize it, and echo it out via PHP.

  11. <?php
  12. $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
  13. echo "<a href='$url'>back</a>";
  14. ?>

No comments:

Post a Comment