无法将google.com作为src添加到IFrame中

时间:2012-08-27 11:51:38

标签: html iframe html4

  

可能重复:
  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测试过它。

为什么?

由于

2 个答案:

答案 0 :(得分:2)

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

请参阅:Mozilla Developer Network - The X-Frame-Options response header

答案 1 :(得分:1)

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

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