0

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?

1
  • This is a breach of privacy. Why do you need to do that? Commented Aug 2, 2014 at 11:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

document.referrer is the JS equivalent of PHP's $_SERVER['HTTP_REFERER'].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.