我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。
是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?
我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。
是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?
当前回答
虽然没有提及,但在某些情况下可以有所帮助:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState !== 4) return;
if (xhr.status === 200) {
var doc = iframe.contentWindow.document;
doc.open();
doc.write(xhr.responseText);
doc.close();
}
}
xhr.open('GET', url, true);
xhr.send(null);
其他回答
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.
X-Frame-Options Allow-From https://..。如果使用Content-Security-Policy报头,则会被替换(并被忽略)。
这里是完整的参考资料:https://content-security-policy.com/
网站所有者使用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 -我已经建立了这两个解决方案,并有第一手的经验。
这就是解决办法!!
FB.Event.subscribe('edge.create', function(response) {
window.top.location.href = 'url';
});
这是唯一适用于facebook应用的方法!
我在mediawiki上遇到了同样的问题,这是因为服务器出于安全原因拒绝将页面嵌入到iframe中。
我写了
$wgEditPageFrameOptions = "SAMEORIGIN";
导入mediawiki PHP配置文件。
希望能有所帮助。