如果在iframe中隐藏标题

编程入门 行业动态 更新时间:2024-10-23 08:30:27
本文介绍了如果在iframe中隐藏标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要隐藏基于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中隐藏标题

本文发布于:2023-10-18 10:51:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504019.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!