我正在使用以下简单的iFrame代码来加载Yahoo,但它无论如何都没有加载.在Chrome Inspector中,我首先看到URL状态为301,然后取消.知道为什么会这样吗?
<iframe name="iframe1" src="http://yahoo.com"></iframe>
Run Code Online (Sandbox Code Playgroud)
iam*_*eed 29
您可能会在日志中看到如下所示的错误消息:
"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>
Run Code Online (Sandbox Code Playgroud)
我没有在这里看到控制台错误,所以我想这就是这种情况.
雅虎!JavaScript是混淆的,但你可以看到他们肯定在这个片段中删除了一些内容.(代码取自雅虎网站)
if(self!==self.top){b=function(){if(g.readyState=="complete"){f.remove(g,e,b);
Run Code Online (Sandbox Code Playgroud)
如果托管网页的站点强制使用安全HTTPS连接,则某些浏览器(当然是 chrome)将要求所有网络资源也使用HTTPS。
您当前 iframe 中的 URL 正在使用 HTTP src="http://yahoo.com"
尝试使用 HTTPS: src="https://yahoo.com"
| 归档时间: |
|
| 查看次数: |
53821 次 |
| 最近记录: |