Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an HTML back link?

What is the simplest way to create an <a> tag that links to the previous web page? Basically a simulated back button, but an actual hyperlink. Client-side technologies only, please.

Edit
Looking for solutions that have the benefit of showing the URL of the page you're about to click on when hovering, like a normal, static hyperlink. I'd rather not have the user looking at history.go(-1) when hovering on a hyperlink. Best I've found so far is:

<script>    document.write('<a href="' + document.referrer + '">Go Back</a>');  </script>

Is document.referrer reliable? Cross-browser safe? I'll be happy to accept a better answer.

like image 633
calebds Avatar asked Jan 11 '12 05:01

calebds


People also ask

How do I make a link go back in HTML?

You can use the history. back() method to tell the browser to go back to the user's previous page. One way to use this JavaScript is to add it to the onclick event attribute of a button. Here, we create the button using a <form> element, containing an <input> element of the button type.


1 Answers

And another way:

<a href="javascript:history.back()">Go Back</a>
like image 173
Bajrang Avatar answered Sep 28 '22 15:09

Bajrang