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?
views:
88answers:
4
A:
No you can't access the parent window if its not on the same domain.
eskimoblood
2010-07-29 15:08:58
what if I own the parent domain, as well?
sprugman
2010-07-29 15:35:11
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
2010-07-29 16:03:11
I wasn't thinking about sub-domains, so much as two separate domains, but where I control the content on both.
sprugman
2010-07-29 16:24:54
`document.domain = 'foo';` throws an error.
sprugman
2010-07-29 16:26:22
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
2010-07-29 18:53:23
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
2010-07-29 16:00:30
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
2010-08-03 21:16:21
+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
2010-08-04 02:17:30
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
2010-08-04 19:29:03
Indeed. I just wanted to give a clear JavaScript answer to the question as stated, in case someone else needed it.
Daniel Cassidy
2010-08-04 23:34:26