我需要隐藏基于 WordPress 的网站的标头,以防该网站加载到 iFrame 中。
我应该用 javascript、函数还是 css 来实现?我该怎么做呢?
我找到了这个
<script type="text/javascript">
var isInIFrame = (window.location != window.parent.location);
if(isInIFrame==true){
alert("It's in an iFrame");
document.getElementById('header').style.display = "none";
}
else {
alert("It's NOT in an iFrame");
}
</script>
但我不知道把它放在哪里(而且我也不知道它是否可行)。
我希望有人能帮助我,谢谢!
我从这篇文章中获取了这段代码(并对其进行了修改以供您使用),所以去那里给格雷格投赞成票:)如何确定网页是在 iframe 内加载还是直接加载到浏览器窗口中?
function inIframe() {
try {
return window.self !== window.top;
} catch () {
return true;
}
}
if(inIframe){
document.getElementById('header').style.display = "none"; //if you want javascript only
$("#header").hide(); // if you want jquery
}
然而,只有当标头具有 ID“标头”时,这才有效。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)