Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i want to know how to access previous page URL through variable??

can i use that variable to compare a URL ??

suppose
var oldUrl = "www.google.com";

if (oldUrl =  "www.google.com")

{
 do some thing

}


scenario like above is possible??
Posted
Updated 24-Nov-15 6:42am
v3
Comments
hypermellow 24-Nov-15 10:51am    
Hi, have a look at JavaScripts "document.referrer" property, as this holds the value of the http referrer. i.e. the address of the page that linked to the current page (if there was one).

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95229140

... hope it helps.
ZurdoDev 24-Nov-15 11:38am    
I would suggest posting as solution.
hypermellow 25-Nov-15 7:06am    
I probably should have posted as a solution, but was having a busy day yesterday. So added a comment to give the OP a nudge in the right direction. :-)
F-ES Sitecore 24-Nov-15 11:11am    
As above use the referrer but not that it isn't guaranteed that this will be populated so don't write anything that relies on it.
Krunal Rohit 24-Nov-15 11:54am    
And as above, always check for the null for the referrer URL.

-KR

1 solution

As mentioned in the comments, you can use document.referrer property but check for null since it is not always filled in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900