google-chrome - 浏览器不允许 iframe 进行重定向?

标签 google-chrome iframe

Google Chrome 23 和 Firefox 18 让我抓狂。 我有一个页面,其中有一个 iframe。 单击按钮时,我希望 iframe 打开 http://images.google.com

问题是 iframe 将尝试访问 http://images.google.com ,但是一旦它收到重定向指令(http://images.google.com 正在发出),它就会停止并且不会呈现页面。这是为什么?有什么解决办法吗?

这是演示该问题的代码片段:

<iframe id="panel" style="height: 800px; width: 100%" sandbox="allow-scripts" src="http://images.google.com">
</iframe> 

最佳答案

这是一个浏览器安全问题,称为 Click-jacking prevention ,其中一部分是检查 HTTP 响应 header ,X-Frame-Options 。此 header 可以采用值 DENY , SAMEORIGIN ,或ALLOW-FROM来源,这将分别阻止任何帧、阻止外部站点帧或仅允许指定站点帧。

简单地说,当此 http header 存在时,它会阻止网站在 <frame> 中呈现。或<iframe> 。自 2009 年以来,大多数浏览器都实现了此 http header ,包括 IE8+、Safari、Firefox、Chrome 和 Opera。

以下是来自 images.google.com 的 header , SAMEORIGIN意味着该地址只能在通过 google.com 浏览时在 iframe 内呈现。

enter image description here

关于google-chrome - 浏览器不允许 iframe 进行重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14504516/

相关文章:

javascript - 脚本添加 iframe 内容在 chrome 中没有用户代理样式

javascript - 如何禁用查看源代码和检查元素

javascript - iframe 内 Web 元素的 QuerySelector

javascript - 如何将内容脚本注入(inject)本地页面

javascript - iframe 404错误

html - 您可以在特定 SVG 元素上禁用 Google Chrome 中的 gpu 光栅化吗?

google-chrome - Google Chrome 开发者工具中的 Step 和 Step Into 有什么区别?

firefox - 将 HTML 5 Canvas 保存到 Chrome 中的文件?

javascript - Rails 无法从 link_to 加载 Chrome 中的 js

html - 在 chrome 上选择删除边框/背景图像(mac)