views:

377

answers:

1

Is it possible to get the referrer of an iFrame's parent page with JavaScript in iFrame?

Example: Page A has an iFrame. The iFrames referrer is be page A. But is is possible to get Page A's referrer in the iFrame with JavaScript?

+3  A: 

This should be:

parent.document.referrer

Anything in the window that creates the iframe should be accessible through the parent scope.

Anthony
They fixed the spelling in the DOM? Cool :)
Chris
How about is there are multiple iframes inside in each other?
Norbert Tamas
@Norbert: I would assume parent.parent to refer to a "grandparent' and so on. I haven't tested. I am wondering now what you're actually doing that brought this up.Edit: Just tested and confirmed, this does work as expected.
Anthony
The easiest way to get the parent (if there are iFrames) referrer in javaScript is: top.document.referrerThis works if the iFrame has the same domain as the parent page and works with multiple iFrames.There is no way to get the parent referrer because of cross browser security if the iFrame and the parent has different domains.
Norbert Tamas