6

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,

Shadow Wizard Says No More War
  • 64,101
  • 26
  • 136
  • 201
EMM
  • 1,762
  • 7
  • 32
  • 58

2 Answers2

5

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.

Community
  • 1
  • 1
Sean Carruthers
  • 394
  • 1
  • 10
3

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>
jerjer
  • 8,574
  • 29
  • 36