我需要隐藏基于wordpress的网站的标题,以防网站加载到iFrame中。 我应该使用javascript,在函数中还是在css中使用它?我该怎么做? 我发现这个
< script type =text / javascript> var isInIFrame =(window.location!= window.parent.location); if(isInIFrame == true){ alert(It is in a iFrame); document.getElementById('header')。style.display =none; } else { alert(它不在iFrame中); } < / script>但是我不知道该放哪里(也不知道它是否可以工作)。 我希望有人能帮助我,谢谢!
解决方案我抓住了这段代码(并修改了它供您使用)从这篇文章,所以去那里,让格雷格upvote :)
p $ p> 函数inIframe(){ try { return window.self!== window.top; } catch(){ return true; } } if(inIframe){ document.getElementById('header')。style.display =none; //如果你只需要javascript $(#header)。hide(); //如果你想要jquery }然而这只有在头部有ID标题。
I need to hide the header of my wordpress-based website, in case the site is loaded in an iFrame. Should I do it with javascript, in functions or in css? And how can I do it? I found this
<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>But I don't where to put it (and also I don't know if it could work). I hope someone can help me, thanks!
解决方案I grabbed this code (and modified it for your use) from this post so go there and give Greg an upvote :) How to identify if a webpage is being loaded inside an iframe or directly into the browser window?
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 }However this will only work if the header has the ID "header".
更多推荐
如果在iframe中隐藏标题
发布评论