johnnyk
johnnyk

Reputation: 3

How get the parent.document.referrer when cross domain?

Here is my problem:

  1. page A in domain X
  2. page B in domain Y
  3. A have a iframe,and link to B

Now i can get the A's location in B by document.referrer,but my boss give me a new task:

get the A's referer

First i tried:parent.document.referrer,it is as expected i encountered this error:"unsafe ... in cross domain".

So,guys,it's possible to get A'referer?How can i do it?

Thanks!

Upvotes: 0

Views: 3618

Answers (1)

Jules
Jules

Reputation: 7223

This is not possible. You can only access the REFERER of the page that is reaching you. You can read more about that here.

You could bypass it though by providing the referer through a querystring variable.

E.g.

<iframe src="http://www.domainy.com?ref=Myreferer"></iframe>

Note though that a REFERER is not always set. Usually (but it varies in the different browsers) it is set when the page is reached by clicking a link, but there will be none when a user navigates directly to your webpage (enters URL in address bar) or by selecting one of his favorites.

Upvotes: 1

Related Questions