【问题标题】:iframe refuses to displayiframe 拒绝显示
【发布时间】:2015-11-03 20:13:43
【问题描述】:

我正在尝试将一个简单的 iframe 加载到我的一个网页中,但它没有显示。我在 Chrome 中收到此错误:

Refused to display 'https://cw.na1.hgncloud.com/crossmatch/index.do' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' https://cw.na1.hgncloud.com".


Invalid 'X-Frame-Options' header encountered when loading 'https://cw.na1.hgncloud.com/crossmatch/index.do': 'ALLOW-FROM https://cw.na1.hgncloud.com' is not a recognized directive. The header will be ignored.

这是我的 iframe 的代码:

<p><iframe src="https://cw.na1.hgncloud.com/crossmatch/" width="680" height="500" frameborder="0"></iframe></p>

我不太确定这意味着什么。我之前加载了很多 iframe,从来没有收到过这样的错误。

有什么想法吗?

【问题讨论】:

    标签: html iframe


    【解决方案1】:

    这意味着cw.na1.hgncloud.com 的 http 服务器发送一些 http 标头来告诉 Chrome 等网络浏览器允许 iframe 仅从托管在同一域 (cw.na1.hgncloud) 上的页面加载该页面 (https://cw.na1.hgncloud.com/crossmatch/) .com):

    Content-Security-Policy: frame-ancestors 'self' https://cw.na1.hgncloud.com
    X-Frame-Options: ALLOW-FROM https://cw.na1.hgncloud.com
    

    您应该阅读:

    【讨论】:

    • src 中使用的资源是否应该发送iframe 的属性Content-Security-Policy
    • ALLOW-FROM in used with X-Frame-Options 现在根据 Mozilla 指南 developer.mozilla.org/en-US/docs/Web/HTTP/Headers/… 已过时。如上所述,您应该更喜欢Content-Security-Policy
    【解决方案2】:

    错误的原因是https://cw.na1.hgncloud.com 的主机服务器提供了一些 HTTP 标头来保护文档。其中之一是框架祖先必须来自与原始内容相同的域。您似乎试图将 iframe 放在与 iframe 内容不同的域位置 - 因此违反了主机设置的内容安全策略。

    查看Content Security Policy 上的此链接了解更多详情。

    【讨论】:

      【解决方案3】:

      对于任何为 IFRAME 回调到同一服务器的任何人,请在 IFRAME 页面中传递这个简单的标头:

      Content-Security-Policy: frame-ancestors 'self'

      或者,将其添加到您的 Web 服务器的 CSP 配置中。

      【讨论】:

        【解决方案4】:

        我也遇到了同样的问题,只是不要在私人窗口中打开页面。

        【讨论】:

          猜你喜欢
          • 2020-12-14
          • 2016-10-12
          • 2016-09-17
          • 2015-11-18
          • 2017-06-05
          • 1970-01-01
          • 1970-01-01
          • 2020-11-19
          • 2020-07-29
          相关资源
          最近更新 更多