Reputation: 69002
Is it possible to get the url of the previous website page from another website domain using javascript, example:
user have this website url in browser:
www.example.com/page1.html
then user cleared the browser address bar and wrote my website
url: www.test.com
What I need is using javascript to get the
www.example.com/page1.html url.
Is that possible?
Upvotes: 0
Views: 2092
Reputation: 5846
No, for the same reasons you can not get the url from an iframe if it's on a different domain: cross-domain security.
What you can do is get the $_SERVER['HTTP_REFERER']
in php but it's not always set...
Or as @FabrícioMatté commented document.referrer
in javascript, but reliability is just as bad.
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
http://php.net/manual/en/reserved.variables.server.php
To go back to the previous page you can use history.go(-1)
in javascript.
Upvotes: 3