我试图在 iframe 中加载页面时隐藏标题和导航栏
我在 html 页面上使用的代码:
<div id="frame2"><iframe width="100%" height="600px" margin-top="-350px" id="frame1" src="http://mls.searchfloridahomelistings.com/i/Neigbs_Bear_Lake_1" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>
我已经尝试了所有我能找到的使用 javascript 的建议,但没有一个有效
当我在谷歌中检查时,我可以添加一个显示:无;到 css 类:navbar-inverse 它隐藏了所有内容,但是当我尝试添加 javascript 时它不起作用:
<script type="text/javascript"> var isInIFrame = (window.location != window.parent.location);if(isInIFrame==true)document.getElementsByClassName("navbar-inverse")[0].style.display = "none";}</script>
我还尝试了此处和其他论坛上其他帖子中给出的示例的几种变体
正在加载的页面是 http://www.searchfloridahomelistings.com/altamonte-springs-homes-for-sale/bear-lake-homes-for-sale/
是否是因为 iframe 的 url 与跨脚本网站的 url 不同?
我对 javascript 不太熟悉,因此我们将不胜感激!
最佳答案
您不能,因为 iframe
有另一个范围,因此您无法使用 JavaScript 访问它以设置样式或更改其内容。
它实际上是另一个页面
关于javascript - 在 iframe 中隐藏导航栏和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42859361/