views:

88

answers:

4

I know that iframed pages can tell that they are, but is it possible to tell where? parent.location runs into security issues when parent is a different domain, as far as I can tell. Any work arounds?

A: 

No you can't access the parent window if its not on the same domain.

eskimoblood
what if I own the parent domain, as well?
sprugman
the it should work. Note that also different subdomains will case the cross domain problem. You can work around this by setting document.domain so taht both have the share the same domain.
eskimoblood
I wasn't thinking about sub-domains, so much as two separate domains, but where I control the content on both.
sprugman
`document.domain = 'foo';` throws an error.
sprugman
So for example you're on myDomian.com and your iframe is on subdomain.myDomain.com, you can set the domain in your parent: $('myIframe').contentWindow.document.domain = myDomain.com. I'm note sure that you can do the same from inside the iframe.
eskimoblood
A: 

Wouldn't it show up in your server logs as the referrer? I know that's not a programmatic way, but i'm wondering if you're just trying to track down people stealing your content.

Shane N
hmm... that might help
sprugman
(it's less about stealing and more about knowing where it's showing up.)
sprugman
(for that matter, I can use `$_SERVER['HTTP_REFERER']` on the back-end to get the same info more directly.) that'll get me to a parent page, but not a grand-parent.
sprugman
A: 

If you wanted to put the effort in, you could write a plugin(for all browsers) or active x(for ie) to determine this as they are not blocked from accessing the clients computer as much as javascript ect.

James
I could write that, but I doubt I could get everyone to install it....
sprugman
+1  A: 

I haven’t tested, but you should be able to do something like:

if (window.top !== window.self) {
    alert("I am a frame. The parent document is " + document.referrer);
}
Daniel Cassidy
Thanks. That's essentially the same method as I mentioned in my comment on Shane N's answer, but on the client side. It'll get me a parent, but not a grand-parent.
sprugman
Indeed. I just wanted to give a clear JavaScript answer to the question as stated, in case someone else needed it.
Daniel Cassidy