How to get previous page URL using javascript?

How to get the URL of the previous page in JavaScript?

Let's say I go from page A to B and use the back-to-back button to return to page A.

I tried to use history.previous , but I can't get it to work.

+59
javascript
Apr 26 2018-11-11T00:
source share
4 answers

To get the previous URL, you can use the following.

 var oldURL = document.referrer; alert(oldURL); 
+86
Apr 26 2018-11-11T00:
source share
— -

Do you want to see page B's page A?

Or find out on page B the URL of page A?

On page B: document.referrer, if installed. As already shown here: How to get the previous URL in JavaScript?

On page A, you will need to read the cookie or local / sessionStorage that you set on page B, provided that the same domains

+8
Apr 26 '11 at 9:02
source share
 <script type="text/javascript"> document.write(document.referrer); </script> 

document.referrer serves your purpose, but does not work for versions of Internet Explorer earlier than IE9.

It will work for other popular browsers like Chrome, Mozilla, Opera, Safari, etc.

+8
Feb 07 '12 at 10:33
source share

you can use the story in this case.

 function backtopage() { window.history.back(); } 

call this function in the "Back" button in the client click event.

This will work.

-one
Jan 17 2018-12-12T00:
source share



All Articles