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,
If you want to go to the previous page without knowing the url, you could use the new History api. history. back(); //Go to the previous page history. forward(); //Go to the next page in the stack history.go(index); //Where index could be 1, -1, 56, etc.
getElementById('previous-page'); previousPage. textContent = document. referrer; Displaying the previous page URL on the visited page.
You can use the document. referrer property to get the previous page URL in JavaScript. It is a read-only property that returns the URL of the document that loaded the current document.
The Document. referrer property returns the URI of the page that linked to this page.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With