【发布时间】:2012-05-03 08:06:00
【问题描述】:
我正在使用以下简单的 iFrame 代码来加载 Yahoo,但无论如何它都没有加载。在 Chrome Inspector 中,我首先看到 URL 状态为 301,然后取消。知道为什么会这样吗?
<iframe name="iframe1" src="http://yahoo.com"></iframe>
【问题讨论】:
-
您可能需要考虑将答案标记为正确。
我正在使用以下简单的 iFrame 代码来加载 Yahoo,但无论如何它都没有加载。在 Chrome Inspector 中,我首先看到 URL 状态为 301,然后取消。知道为什么会这样吗?
<iframe name="iframe1" src="http://yahoo.com"></iframe>
【问题讨论】:
您可能会在日志中收到一条错误消息,内容如下:
"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
【讨论】:
如果您在使用简单 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 被混淆了,但你可以看到他们肯定在这个 sn-p 中删除了一些东西。 (代码取自雅虎网站)
if(self!==self.top){b=function(){if(g.readyState=="complete"){f.remove(g,e,b);
【讨论】:
实际上 yahoo 、 google 和此类网站不允许 iframe 进入他们的网站。他们阻止 iframe 显示他们的网站
【讨论】:
如果托管网页的站点强制使用安全的HTTPS 连接,则某些浏览器(当然是chrome)将要求所有网络资源也使用HTTPS。
您当前 iframe 中的 URL 使用的是 HTTP src="http://yahoo.com"
尝试使用 HTTPS:src="https://yahoo.com"
【讨论】:
当父级未加密时,我最新的 Firefox 默默地拒绝加载未加密的 iframe。它没有显示有关尝试加载孩子或任何不尝试这样做的理由的控制台消息。
【讨论】: