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 The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
EMM
  • 1,812
  • 8
  • 36
  • 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
  • 414
  • 2
  • 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,694
  • 30
  • 36