“Go Back” Button

0
0

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>"; 
?>
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.