iFrame没有加载URL

时间:2012-04-22 13:14:16

标签: html iframe

我正在使用以下简单的iFrame代码来加载Yahoo,但无论如何它都没有加载。在Chrome Inspector中,我首先看到URL状态为301,然后取消。知道为什么会这样吗?

<iframe name="iframe1" src="http://yahoo.com"></iframe>

5 个答案:

答案 0 :(得分:28)

您可能会在日志中看到如下所示的错误消息:

"Refused to display document because display forbidden by X-Frame-Options."

回答你的问题:

雅虎正在对avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

这样做

欲了解更多信息,请阅读: https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header

答案 1 :(得分:6)

如果您使用简单的javascript在iframe中,也很容易要求网站不加载。例如,twitter就是这样做的

<script type="text/javascript">
//<![CDATA[
    if (window.top !== window.self) {
        document.write = "";
        window.top.location = window.self.location;
        setTimeout(function () {
            document.body.innerHTML = '';
        }, 1);
        window.self.onload = function (evt) {
            document.body.innerHTML = '';
        }; 
    }
//]]>
</script>

我在这里没有看到控制台错误,所以我猜这就是这种情况。

雅虎! JavaScript是混淆的,但你可以看到他们肯定在这个片段中删除了一些内容。 (代码取自雅虎网站)

if(self!==self.top){b=function(){if(g.readyState=="complete"){f.remove(g,e,b);

答案 2 :(得分:3)

实际上雅虎,谷歌和这样的网站不允许iframe到他们的网站。他们阻止iframe显示他们的网站

答案 3 :(得分:2)

如果托管网页的网站强制使用安全HTTPS连接,则某些浏览器(肯定是chrome)将要求所有网络资源也使用HTTPS

当前iframe中的网址使用的是HTTP src="http://yahoo.com"

尝试使用HTTPS:src="https://yahoo.com"

答案 4 :(得分:0)

当父级未加密时,我最新的Firefox默默拒绝加载未加密的iframe。它没有显示有关尝试加载子项或任何不尝试加载子项的控制台消息。