我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。
是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?
我正在写一个小网页,它的目的是框架其他一些页面,只是为了将它们合并到一个浏览器窗口中,以便于查看。一些页面,我试图框架禁止被框架,并抛出“拒绝显示文档,因为显示禁止X-Frame-Options.”错误在Chrome。我知道这是一个安全限制(有充分的理由),并且无法更改它。
是否有任何替代的框架或非框架方法来在单个窗口中显示页面,而不会被X-Frame-Options报头绊倒?
当前回答
我有这个问题,并解决了它编辑httd.conf
<IfModule headers_module>
<IfVersion >= 2.4.7 >
Header always setifempty X-Frame-Options GOFORIT
</IfVersion>
<IfVersion < 2.4.7 >
Header always merge X-Frame-Options GOFORIT
</IfVersion>
</IfModule>
我把SAMEORIGIN改成了GOFORIT 并重新启动服务器
其他回答
如果在尝试嵌入Vimeo内容时遇到此错误,请更改iframe的src,从:https://vimeo.com/63534746更改为:http://player.vimeo.com/video/63534746
使用下面给出的这一行,而不是header()函数。
echo "<script>window.top.location = 'https://apps.facebook.com/yourappnamespace/';</script>";
将外部网站加载到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请求,可能是一个普通的浏览器页面访问。
注意:您可能需要改进此脚本中的安全性。因为黑客可以通过你的代理脚本开始加载网页。
虽然没有提及,但在某些情况下可以有所帮助:
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.