Iframe 内容 Blocked
快速摘要
你的 iframe 是空白因为目标 site 发送 X-Frame-Options or CSP 请求头那个 prevent embedding.
为什么发生
目标 site 发送 X-Frame-Options: DENY or SAMEORIGIN
CSP frame-ancestors directive 块 embedding
iframe src URL 是错误 or 返回 404
Mixed 内容: HTTPS page trying 到 embed HTTP iframe
最小示例
<!-- Target site sends X-Frame-Options: DENY -->
<iframe src="https://other-site.com/page"></iframe>
<!-- Console: Refused to display in a frame --><!-- If you control the target server, set: -->
<!-- X-Frame-Options: SAMEORIGIN -->
<!-- Or CSP: frame-ancestors https://your-site.com -->
<iframe src="https://your-site.com/page" sandbox="allow-same-origin"></iframe>目标 site 块 embedding 通过 X-Frame-Options or CSP. 如果你 control 服务器, adjust 请求头到 允许你的原点. Use sandbox for security.
如何诊断
检查浏览器 console for X-Frame-Options or CSP 错误
Inspect 响应请求头的 iframe URL
验证 iframe src URL 是正确 and accessible
如何修复
如果你 control 目标服务器, 移除 or adjust X-Frame-Options and CSP 请求头
Use frame-ancestors in CSP 到 explicitly 允许你的原点
Fix iframe src URL 如果它 是错误
Use HTTPS:// for iframe src on HTTPS pages
如何预防
配置 X-Frame-Options and CSP frame-ancestors intentionally
测试 iframe embedding 期间 development
Use sandbox attribute on iframes for additional security control
相关资源
相关课程
- Web Security 基础
Web security 请求头.