Emily
Emily

Reputation: 1

linking to the previous page javascript document.referrer

I am trying to implement a link that will take me back to the page it last came from. So on site A I submit a form and it goes to site B where when a link is clicked it should go to site A.

here are the code for the two pages. site A:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<a href="http://www.example.com/testbackpage2.html">link to page 2</a>
<p>My first paragraph.</p>

</body>
</html>

site B:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<script type="text/javascript">
var ex=document.referrer;
document.write(ex);
</script>
<a href="ex">go back to page one</a>
<p>My first paragraph.</p>

</body>
</html>

</body>
</html>

Upvotes: 0

Views: 5628

Answers (4)

very tall
very tall

Reputation: 64

top.location = document.referrer;

Upvotes: 1

Praveen Kumar Sharma
Praveen Kumar Sharma

Reputation: 61

use simple to go back in Jswindow.location = document.referrer;

Upvotes: 0

Sunil Dora
Sunil Dora

Reputation: 1472

You can try like this

(How to get previous page url using jquery)

$(document).ready(function() {
  var referrer =  document.referrer;
});

Or

you can also try,

<a href="javascript: history.go(-1)">Back</a>

From this link

Hope it helps.

Upvotes: 0

Jamiec
Jamiec

Reputation: 136134

To go back one page simply use window.history.go(-1) or window.history.back()

<a href="#" onclick="window.history.go(-1)">go back to page one</a>

More info on this API can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Window/history

Upvotes: 1

Related Questions