拒绝在框架中显示网站,因为它的“X框架选项”

Refused to display a website in a frame because of its 'X-Frame-Options'

本文关键字:框架 选项 显示 网站 拒绝 因为      更新时间:2023-09-26

我正在尝试在仅包含iframe的简单HTML页面中显示Facebook页面。

这是我的HTML代码:

<html>
    <body>
        <iframe src="http://www.facebook.com"></iframe>
    </body>
</html>

我总是在谷歌浏览器的控制台中收到此错误:

拒绝在帧中显示"http://www.facebook.com/",因为它 将"X 帧选项"设置为"DENY"。

顺便说一句,我在使用这些 iframe 时也遇到了这个问题:

<iframe src="https://mail.google.com/mail/mu/mp/any"></iframe>
<iframe src="http://m.facebook.com"></iframe>
<iframe src="http://m.youtube.com"></iframe>
<iframe src="http://m.dropbox.com"></iframe>
<iframe src="http://m.yahoo.com"></iframe>
<iframe src="http://www.google.com"></iframe>
<iframe src="http://mail.google.com"></iframe>
<iframe src="http://www.facebook.com"></iframe>
<iframe src="http://www.youtube.com"></iframe>
<iframe src="http://www.dropbox.com"></iframe>
<iframe src="http://www.yahoo.com"></iframe>

同时,这个iframe运行良好!

<iframe src="http://www.google.com/custom"></iframe>

如何解决这个问题?

根据评论进行编辑:
如果这无法解决,是否有使用 iframe 的替代方案?像XUL中的browser标签?我已经在Firefox扩展程序中尝试了浏览器标签并且效果很好,但是我现在正在编写chrome扩展程序,所以我不能再依赖XUL了?

是的,你可以

  • 使用服务器端包含,从服务器获取它并将其包含在 iframe 中
  • 使用无法识别该标头的自定义浏览器
  • 复杂:使用 websockets 创建自己的 Javascript HTTP 客户端,获取页面,并将其插入到 DOM 中

对于那些感兴趣的人,这是无法做到的!