在contentArea中添加Iframe之后,我得到了两个滚动条。我想隐藏iframe滚动条而不隐藏外部网站链接的任何内容。我怎样才能做到这一点?
我添加了以下代码段代码,并尝试了scrollbar="no"
之类的几件事,但是没有用。
帮助我,在此先感谢您。
body{margin:0;padding:0;}
.contentArea{height:100%; width:100%; position:absolute; top:0;left:0;overflow-y:scroll;}
iframe{height:100%; width:100%; position:absolute; top:0;left:0;border:0;}
<div class="contentArea">
<iframe src="https://ajaymalhotra.in" title="Iframe Example"></iframe>
</div>
最佳答案
您需要使iframe的大小与iframe中内容的大小匹配。它们不是在浏览器中执行此操作的 native 方法,如果您执行此跨域操作,则您将需要在父级和iframe中都使用JS代码。
这是我几年前写的关于如何执行此操作的更长的答案。
iframe Auto Adjust Height as content changes
另外,他们是这个库,它将使您的事情变得简单得多。
https://github.com/davidjbradshaw/iframe-resizer