Wednesday, February 22, 2012

Novice Tip : Create custom Back link


Everyone on earth has the right to create his own website. Today's tip is a very very novice trick but useful.

What if you needed to create a link that refers you to the previous page !? i know that the Back button in all browsers do this feature ... but now you can implement this also inside your site ( may be for design issues ). To create such a link ( or button ), you need to add a javascript function in your Link mouse click event.
Example :

< a href="#" onclick="history.back(-1)"> Back </a>

This snippet will create a Back link, that will look up your history and go back one step. You don't need to add any javascript file to do this.

Now after we know the easy way, there is another way using PHP. This can be used if javascript is not available or if the javascript solution didn't work ( rarely happen ) !!

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


Enjoy Development :)

No comments:

Post a Comment