Skip to content
IframeViewer

指南

iframe 为什么被拦截 — 以及如何应对

Iframe Viewer 所知的一切,写成文字。浏览标题,或直接跳到 sandbox 表格。

X-Frame-Options

最早的反点击劫持响应头。服务器将其加入响应,告知浏览器该文档是否可在 <frame>、<iframe>、<embed> 或 <object> 中渲染。

DENY

永不允许嵌入,即使是同一站点。

SAMEORIGIN

仅允许同源页面嵌入。

ALLOW-FROM uri

已废弃。现代浏览器忽略 — 请改用 CSP。

响应头
HTTP/2 200
X-Frame-Options: SAMEORIGIN

Content-Security-Policy: frame-ancestors

现代替代方案。支持允许的父级源列表、通配符和协议。两者同时存在时,支持 frame-ancestors 的浏览器会忽略 X-Frame-Options。

仅允许自己的网站和一个合作方
Content-Security-Policy: frame-ancestors 'self' https://*.partner.com
拦截所有嵌入
Content-Security-Policy: frame-ancestors 'none'

注意镜像指令:您页面上的 frame-src 控制您可以嵌入哪些 URL。如果嵌入在 Iframe Viewer 上正常而在您的网站上失败,请先检查自己的 CSP。

sandbox 标志

空的 sandbox 属性会移除所有能力。逐一加回所需的标记。

标记授予
allow-scripts允许框架内页面运行 JavaScript。
allow-same-origin保留页面的源(Cookie、存储)。与 scripts 同用时,同源内容的 sandbox 将失效。
allow-forms允许提交表单。
allow-popups允许 window.open 与 target=_blank。
allow-popups-to-escape-sandbox打开的窗口不受 sandbox 限制。
allow-modalsalert()、confirm()、prompt()、print()。
allow-top-navigation允许框架导航您的页面。
allow-top-navigation-by-user-activation仅在点击/触摸后允许顶层导航。
allow-downloads允许由框架发起的文件下载。
allow-presentationPresentation API(投屏)。
allow-pointer-lockPointer Lock API(游戏)。
allow-orientation-lock屏幕方向锁定。

Permissions Policy(allow)

sandbox 移除能力,而 allow 则把强大功能委托给框架。每一项是功能名称,可选地后跟允许列表。

<iframe
  src="https://player.example.com/v/123"
  allow="fullscreen; autoplay; picture-in-picture; clipboard-write"
  allowfullscreen
></iframe>

哪些网站允许嵌入?

测试工具使用的数据库。均为观测值 — 可能随时变化;上线前请用 curl 命令确认。

域名嵌入响应头 / 替代方案
google.com拦截X-Frame-Options: SAMEORIGINGoogle Maps and YouTube expose dedicated /embed endpoints instead.
youtube.com拦截X-Frame-Options: SAMEORIGINUse https://www.youtube.com/embed/VIDEO_ID for embedding.
facebook.com拦截X-Frame-Options: DENYUse the official Facebook Page/Post plugins.
instagram.com拦截X-Frame-Options: SAMEORIGINUse instagram.com/p/ID/embed/ for public posts.
twitter.com拦截X-Frame-Options: DENYUse publish.twitter.com to get a widget snippet.
x.com拦截X-Frame-Options: DENYUse publish.twitter.com to get a widget snippet.
linkedin.com拦截X-Frame-Options: SAMEORIGIN
github.com拦截X-Frame-Options: DENYGists can be embedded via the script snippet on each gist.
amazon.com拦截X-Frame-Options: SAMEORIGIN
netflix.com拦截X-Frame-Options: DENY
reddit.com拦截content-security-policy: frame-ancestors 'self'Use embed.reddit.com for individual posts.
stackoverflow.com拦截X-Frame-Options: SAMEORIGIN
paypal.com拦截X-Frame-Options: SAMEORIGIN
apple.com拦截X-Frame-Options: SAMEORIGIN
microsoft.com拦截X-Frame-Options: SAMEORIGIN
openai.com拦截content-security-policy: frame-ancestors 'none'
chatgpt.com拦截content-security-policy: frame-ancestors 'none'
notion.so拦截X-Frame-Options: SAMEORIGINPublic pages can be embedded via notion.site links in some tools.
figma.com拦截X-Frame-Options: SAMEORIGINUse the /embed?embed_host=... URL from Share → Get embed code.
wikipedia.org允许(no framing restriction)Wikipedia allows framing.
example.com允许(no framing restriction)
codepen.io允许(embeds allowed via /embed/ URLs)Use the Embed button on a pen for the canonical snippet.
vimeo.com拦截X-Frame-Options: SAMEORIGINUse https://player.vimeo.com/video/ID.
player.vimeo.com允许(embed endpoint)
open.spotify.com拦截X-Frame-Options: SAMEORIGINUse https://open.spotify.com/embed/... URLs.
maps.google.com拦截X-Frame-Options: SAMEORIGINUse the Share → Embed a map snippet.

常见问题

为什么 iframe 显示空白或“拒绝连接”?

该网站发送了 X-Frame-Options 响应头(DENY 或 SAMEORIGIN),或带有不包含您的源的 frame-ancestors 指令的 Content-Security-Policy。浏览器遵守该策略并改为显示错误页。可在 DevTools → Console 或通过 Iframe Viewer 提供的 curl 命令查看确切响应头。

如何测试一个网站能否嵌入 iframe?

把 URL 粘贴到上方的测试工具并点击「渲染」。Iframe Viewer 会在您选择的设备尺寸下用真实 iframe 加载它,并报告加载是否成功、由哪个依据判定以及耗时。

Iframe Viewer 能直接读取 X-Frame-Options 响应头吗?

仅靠浏览器不行 — 跨源响应头在设计上对 JavaScript 隐藏。Iframe Viewer 结合确定性检查(混合内容、热门网站数据库)、浏览器 load 事件和同源探测,并始终告诉您判定依据。要获得确切答案,请使用 curl 命令。

测试工具说“load 事件已触发”,但我仍看到错误页。哪个是对的?

都对。Chrome 和 Firefox 即使替换为错误页也会触发 load,因此仅凭该事件无法区分成功与拦截。请以肉眼判断为准,并用 curl 确认。

Iframe Viewer 会存储或记录我测试的 URL 吗?

不会。没有服务器。历史记录保存在浏览器的 localStorage 中以便刷新后保留,可一键清除。若您同意统计,Analytics 也只统计页面浏览和按钮点击 — 绝不记录您测试的 URL。

allow 和 sandbox 有什么区别?

sandbox 移除能力(脚本、表单、弹窗、导航),您只加回需要的部分。allow 是针对摄像头、全屏、支付等强大功能的 Permissions Policy。对不受您控制的第三方内容,两者都应使用。

为什么在这里能嵌入,在我的网站上却不行?

常见原因:您的页面是 HTTPS 而目标是 HTTP(混合内容);目标检查 Referer 头;或您自己网站的 Content-Security-Policy 中 frame-src 不包含目标。可在「框架选项」中尝试 referrer 策略。

Iframe Viewer 真的免费吗?

是的 — 完全免费,无需账户,没有限制。它是一个静态网站,没有需要回收的服务器成本。