EMM
EMM

Reputation: 1812

Fetching the url of previous page in html?

I have an HTML page which contains an href tag.
On clicking href link, I get a new page opened.
What I want to do is fetch the url of the previous page, on which I had the href link, in my current page.

Please help. Thanks,

Upvotes: 6

Views: 10809

Answers (2)

Sean Carruthers
Sean Carruthers

Reputation: 414

How to get previous page url using jquery

With jQuery 'wrapper' of sorts:

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

Or you can just integrate var referrer = document.referrer; into your plain javascript.

Upvotes: 5

jerjer
jerjer

Reputation: 8768

try getting the referrer URL or you can also pass the previous url in the href link:

for passing the the prev url to the href link you can you can use javascript:

<a href="newurl.html" id="link1">kdjfdkjfkdjf</a>

<script>
   window.onload = function(){
     var a = document.getElementById("link1");
     a.href = a.href + "?prevurl=" + escape(document.location.href);
   }
</script>

Upvotes: 3

Related Questions