Go Back button with Javascript

Filed Under (JavaScript) by khawaib on 06-04-2010

Tagged Under : , , , , ,

JavaScript:
Use inline JavaScript to send user back to previous page.

<input type="button" value="Go Back" onclick="history.back(-1)" />

Can also send user two steps back as well.

<input type="button" value="Go Back" onclick="history.back(-2)" />

PHP:
PHP code to send user back.

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