Extract url of previous page in html?

I have an HTML page containing an href tag.
When I click the href link, I open a new page.
What I want to do is get the URL of the previous page on which I had the href link on my current page.

Please, help. Thanks,

+4
source share
2 answers

How to get previous page url using jquery

With jQuery 'wrapper' kind:

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

Or you can simply integrate var referrer = document.referrer; into your simple javascript.

+3
source

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

to pass the previous url to the href link 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> 
+2
source

Source: https://habr.com/ru/post/1398970/


All Articles