Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching the url of previous page in html?

Tags:

html

referrer

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,

like image 395
EMM Avatar asked Feb 29 '12 08:02

EMM


People also ask

How do I find the previous URL in HTML?

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.

How do I find the last page URL?

getElementById('previous-page'); previousPage. textContent = document. referrer; Displaying the previous page URL on the visited page.

How do I find an old URL?

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.

What is document referrer?

The Document. referrer property returns the URI of the page that linked to this page.


2 Answers

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.

like image 168
Sean Carruthers Avatar answered Nov 12 '22 19:11

Sean Carruthers


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>
like image 30
jerjer Avatar answered Nov 12 '22 20:11

jerjer