can't add google.com as src to an IFrame [duplicate]

天大地大妈咪最大 提交于 2019-12-13 04:07:27

问题


Possible Duplicate:
How to show google.com in an iframe?

Why some websites can't be added as source to my iframe

I have this code:

<!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>

If i change http://www.example.com to http://www.google.com it doesn't show any content. I have tested it with chrome, IE, FF.

Why is that?

Thanks


回答1:


Google sets the x-frame-options response header to SAMEORIGIN

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




回答2:


Google is sending an "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page

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



来源:https://stackoverflow.com/questions/12141436/cant-add-google-com-as-src-to-an-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!