我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。

是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?


当前回答

这就是解决办法!!

FB.Event.subscribe('edge.create', function(response) {
    window.top.location.href = 'url';
});

这是唯一适用于facebook应用的方法!

其他回答

I came across this issue when running a wordpress web site. I tried all sorts of things to fix it and wasn't sure how, ultimately the issue was because I was using DNS forwarding with masking, and the links to external sites were not being addressed properly. i.e. my site was hosted at http://123.456.789/index.html but was masked to run at http://somewebSite.com/index.html. When i entered http://123.456.789/index.html in the browser clicking on those same links resulted in no X-frame-origins issues in the JS console, but running http://somewebSite.com/index.html did. In order to properly mask you must add your host's DNS name servers to your domain service, i.e. godaddy.com should have name servers of example, ns1.digitalocean.com, ns2.digitalocean.com, ns3.digitalocean.com, if you were using digitalocean.com as your hosting service.

如果你试图在iframe中嵌入谷歌Map时遇到这个错误,你需要在源链接中添加&output=embed。

令人惊讶的是,这里没有人提到Apache服务器的设置(*.conf文件)或.htaccess文件本身是导致这个错误的原因。搜索你的。htaccess或Apache配置文件,确保你没有以下设置为DENY:

报头总是设置X-Frame-Options DENY

将其更改为SAMEORIGIN,使事情按预期工作:

报头总是设置X-Frame-Options SAMEORIGIN

网站所有者使用X-Frame-Options响应报头,这样他们的网站就不能在Iframe中打开。这有助于保护用户免受点击劫持攻击

如果你想在自己的机器上禁用X-Frame-Options,可以尝试几种方法。

服务器端配置

如果您拥有服务器或可以与站点所有者合作,那么您可以要求设置一个配置,以根据某些条件不发送Iframe buster响应标头。条件可以是额外的请求头或URL中的参数。

例如,站点所有者可以添加一个额外的代码,当站点打开时不发送Iframe buster报头,使用?in_debug_mode=true查询参数。

使用浏览器扩展,如Requestly删除响应头

您可以使用任何浏览器扩展,如Requestly,它允许您修改请求和响应头。这里有一个Requestly博客,解释了如何在Iframe中嵌入站点,绕过Iframe buster头。

配置一个直通代理,并从它删除标题

如果你需要为多人绕过Iframe buster报头,那么你也可以配置一个直通代理,它只删除帧buster响应报头并返回响应。然而,这是一个非常复杂的编写和设置。还有一些其他的挑战,比如通过代理在Iframe中打开的站点的身份验证等,但这种方法可以很好地用于简单的站点。

PS -我已经建立了这两个解决方案,并有第一手的经验。

将外部网站加载到iFrame的解决方案,即使外部网站的x帧选项设置为拒绝。

如果你想将其他网站加载到iFrame中,而你得到了X-Frame-Options禁止显示的错误,那么你实际上可以通过创建一个服务器端代理脚本来克服这个问题。

iFrame的src属性可以有这样一个url:/ proxy.php?url=https://www.example.com/page&key=somekey

那么proxy.php看起来就像这样:

if (isValidRequest()) {
   echo file_get_contents($_GET['url']);
}

function isValidRequest() {
    return $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['key']) && 
    $_GET['key'] === 'somekey';
}

这通过传递块,因为它只是一个GET请求,可能是一个普通的浏览器页面访问。

注意:您可能需要改进此脚本中的安全性。因为黑客可以通过你的代理脚本开始加载网页。