【问题标题】:can't add google.com as src to an IFrame [duplicate]无法将 google.com 作为 src 添加到 IFrame [重复]
【发布时间】:2012-08-27 11:51:37
【问题描述】:

可能重复:
How to show google.com in an iframe?

为什么有些网站不能作为源添加到我的 iframe

我有这个代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script>
        function changeIframe(newLocation){
            document.getElementById("myIframe").src=newLocation;
        }
        </script>
    </head>
    <body onload="changeIframe('http://www.example.com')">
        <div style="width:650px;float:auto;border:1px dotted #cccccc;">
            <iframe id="myIframe" src="http://www.ebay.co.uk/" width="100%" height=750px marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=1 scrolling=auto>
              <p>Your browser does not support iframes.</p>
            </iframe>
        </div>
    </body>
</html>

如果我将 http://www.example.com 更改为 http://www.google.com 它不会显示任何内容。我用chrome、IE、FF测试过。

这是为什么呢?

谢谢

【问题讨论】:

  • 无法删除,因为有答案

标签: html iframe html4


【解决方案1】:

Google 正在发送“X-Frame-Options: SAMEORIGIN”响应标头。此选项可防止浏览器显示与父页面不在同一域中的 iFrame

见:Mozilla Developer Network - The X-Frame-Options response header

【讨论】:

    【解决方案2】:

    Google 将 x-frame-options 响应标头设置为 SAMEORIGIN

    https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header

    【讨论】:

      猜你喜欢
      • 2012-08-29
      • 2013-04-25
      • 2011-10-21
      • 1970-01-01
      • 2012-05-10
      • 2022-01-17
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多