Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Web Technology by (20.3k points)

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.

1 Answer

0 votes
by (40.7k points)

Try using the code given below:

<a href="javascript:history.back()">Go Back</a>

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...