防止iframe偷窃

Dav*_*801 10 html javascript php iframe jquery

我认为有人正在使用iframe窃取我的内容.我的网站是一个论坛,用户刚刚向我报告.

如果他们是其他人这样做,我怎么能以编程方式(php,JavaScript,jQuery,HTML)找到他们的网站?

这是允许他们在互联网上这样做,我可以采取行动吗?

Hus*_*ein 25

使用JavaScript,您可以做到

if(window.top==window){
 //not inside iframe
} else {
    if(parent.parent.someFunction){
       parent.parent.someFunction();
    } else {
       alert("framing is not allowed")
    }
}
Run Code Online (Sandbox Code Playgroud)

要么

if (window.top !== window.self) window.top.location.replace(window.self.location.href);
Run Code Online (Sandbox Code Playgroud)

一些现代浏览器也支持X-FRAME-OPTIONS标头,它可以有两个值:

* DENY – prevents the page from being rendered if it is contained in a frame
* SAMEORIGIN – same as above, unless the page belongs to the same domain as the top-level frameset holder.
Run Code Online (Sandbox Code Playgroud)

支持标题的浏览器:

* IE8 and IE9
* Opera 10.50
* Safari 4
* Chrome 4.1.249.1042
* Firefox with NoScript
Run Code Online (Sandbox Code Playgroud)