我正在尝试将一个简单的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,但从未收到过这样的错误。
有什么想法吗?
由于
答案 0 :(得分:42)
这意味着cw.na1.hgncloud.com
处的http服务器会发送一些http标头,以告知Chrome等网络浏览器仅允许从同一域上托管的网页加载该网页(https://cw.na1.hgncloud.com/crossmatch/)(cw .na1.hgncloud.com):
Content-Security-Policy: frame-ancestors 'self' https://cw.na1.hgncloud.com
X-Frame-Options: ALLOW-FROM https://cw.na1.hgncloud.com
你应该读到:
答案 1 :(得分:8)
错误的原因是https://cw.na1.hgncloud.com的主机服务器提供了一些HTTP标头来保护文档。其中之一是框架祖先必须来自与原始内容相同的域。您似乎试图将iframe放在与iframe内容不同的域位置 - 因此违反了主机设置的内容安全策略。
请查看Content Security Policy上的此链接了解详情。
答案 2 :(得分:0)
对于您为IFRAME调用同一服务器的任何人,请在IFRAME页面内传递以下简单标头:
Content-Security-Policy: frame-ancestors 'self'
或者,将其添加到Web服务器的CSP配置中。