【问题标题】:Web content is not loading in iframe [duplicate]网页内容未在 iframe 中加载 [重复]
【发布时间】:2014-07-25 07:09:30
【问题描述】:

我的页面中有一个 iframe,它将加载本地 html 内容但不加载远程 Web 内容。

代码如下:

<iframe id="frame1" src="http://localhost/test.html" width="520px" height="400px" scrolling="auto"></iframe>

这是有效的。

但以下代码不起作用:

<iframe id="frame1" src="http://www.google.co.in/" width="520px" height="400px" scrolling="auto"></iframe>

请帮忙

【问题讨论】:

  • 第二个需要互联网连接才能工作。
  • 是的,有网络连接,,,

标签: javascript html iframe


【解决方案1】:

Google 使用 X-FRAME-OPTIONS HTTP 标头来禁止将其页面放入 iframe:https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header

几乎所有现代浏览器都会拒绝将带有此 HTTP 标头的页面放入 iframe 中。对此你无能为力。

【讨论】:

  • 感谢您的回答。非常有帮助:-)
【解决方案2】:

如果您查看控制台,您会看到:

[Error] Refused to display 'https://www.google.co.in/?gws_rd=ssl' in a frame
because it set 'X-Frame-Options' to 'SAMEORIGIN'.

这意味着 Google 不想在 iframe 中显示。

更多关于X-Frame-Options

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    相关资源
    最近更新 更多