admin管理员组文章数量:1246514
We've been having an problem recently where other sites are running our e-merce site inside a frameset where our site (with the offenders affiliate id tacked on) is the only content in a single full width frame. So essentially it looks and feels like our site with their URL at the top. We can cut off their affiliate id, which would make it pointless for them to do, but this doesn't prevent future offenders from doing the same thing until we find out about it.
Is there a generic way (through JavaScript that appears on every page perhaps?) to prevent this from happening? Note that adding targets to to all links is not feasible, but adding a snippet of JS to all pages is, since the header and footer portions are shared sitewide from a single source.
Another possibility would be at the Apache level (if there is anything we could do server side) as we do pass all requests through mod-rewrite.
Note that it would be essential to sill allow pages to load inside an IFrame if the parent page originates from our domain, as we make valid use of IFrames
We've been having an problem recently where other sites are running our e-merce site inside a frameset where our site (with the offenders affiliate id tacked on) is the only content in a single full width frame. So essentially it looks and feels like our site with their URL at the top. We can cut off their affiliate id, which would make it pointless for them to do, but this doesn't prevent future offenders from doing the same thing until we find out about it.
Is there a generic way (through JavaScript that appears on every page perhaps?) to prevent this from happening? Note that adding targets to to all links is not feasible, but adding a snippet of JS to all pages is, since the header and footer portions are shared sitewide from a single source.
Another possibility would be at the Apache level (if there is anything we could do server side) as we do pass all requests through mod-rewrite.
Note that it would be essential to sill allow pages to load inside an IFrame if the parent page originates from our domain, as we make valid use of IFrames
Share Improve this question edited Jul 27, 2012 at 13:42 casperOne 74.5k19 gold badges189 silver badges260 bronze badges asked Jan 20, 2009 at 1:15 PeterPeter 29.9k22 gold badges91 silver badges126 bronze badges4 Answers
Reset to default 6I've heard of solutions to this problem being referred to as a "frame popper script". A quick google es up with this thread. Looks like this is one of the simplest:
if (window != top) top.location.href = location.href;
I believe the proper modern method to achieve this is with The X-Frame-Options response header.
From the MDN:
The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a frame or iframe. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.
Take a look at: How to prevent IFRAME from redirecting top-level window
Take a look at this article. It offers a fairly simple solution for detecting frames and breaking out of them.
How to Break Out of Frames with JavaScript
In addition, I would take it one step further. Whenever you detect a frame, grab the affiliate ID of the offending site framer, and push that to the server with AJAX along with the URL they are using. Then, either automatically or manually, you can verify that they are framing your site, and cancel their affiliate code one at a time.
Just guessing here...but what if you use javascript to call your parent window to access its document object ? You could check if its not null, and if there is a parent window (meaning a frame loaded your site), you could hide all your html through javascript...
本文标签:
版权声明:本文标题:javascript - Possible to prevent our website from running inside another domain's frameset or IFrame? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740261667a2250390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论