Fetching the url of previous page in html?

EMM picture EMM · Feb 29, 2012 · Viewed 9.5k times · Source

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,

Answer

Sean Carruthers picture Sean Carruthers · Feb 29, 2012

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.