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

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


当前回答

这就是解决办法!!

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

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

其他回答

虽然没有提及,但在某些情况下可以有所帮助:

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);

我在mediawiki上遇到了同样的问题,这是因为服务器出于安全原因拒绝将页面嵌入到iframe中。

我写了

$wgEditPageFrameOptions = "SAMEORIGIN"; 

导入mediawiki PHP配置文件。

希望能有所帮助。

使用下面给出的这一行,而不是header()函数。

echo "<script>window.top.location = 'https://apps.facebook.com/yourappnamespace/';</script>";

我有这个问题,并解决了它编辑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 并重新启动服务器

更新2019:您可以使用客户端JavaScript和我的X-Frame-Bypass Web组件绕过<iframe>中的X-Frame-Options。下面是一个演示:x帧旁路中的黑客新闻。(在Chrome和Firefox中测试。)