我正在尝试使用
制作一些应用程序<iframe src="https://www.google.com" style="height: 100%;width: 100%"></iframe>
但由于某种原因,它无法正常工作
答案 0 :(得分:8)
大多数主要网站都会阻止自己加载到iframe中以避免Clickjacking。
Google 通过在其响应标头中强制执行 X-Frame-Options:SAMEORIGIN 来防止这种情况发生。
Gmail的情况也是如此。
Facebook 正在使用此回复标题 X-Frame-Options:Deny
使用X-Frame-Options
X-Frame-Options有三种可能的值:
DENY
无论网站是否尝试这样做,页面都无法在框架中显示。
SAMEORIGIN
页面只能显示在与页面本身相同的原点的框架中。
允许来自 uri
页面只能显示在指定原点的框架中。
Twitter曾经有过像这样的另一个JavaScript黑客
<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);
两者本质上意味着,如果在iframe中加载,则清除body.innerHTML / remove。
Twitter 现在在其响应标头中强制执行 X-Frame-Options:SAMEORIGIN 。
答案 1 :(得分:0)