不使用滚动条让iframe根据内容自动调整高度? [英] Make iframe automatically adjust height according to the contents without using scrollbar?
本文介绍了不使用滚动条让iframe根据内容自动调整高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
<iframe name="Stack" src="http://stackoverflow.com/" width="740"
frameborder="0" scrolling="no" id="iframe"> ...
</iframe>
我希望它能够根据里面的内容调整它的高度,而不是使用滚动.
I want it to be able to adjust its height according to the contents inside it, without using scroll.
推荐答案
将此添加到您的 部分:
Add this to your <head>
section:
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
}
</script>
并将您的 iframe 更改为:
And change your iframe to this:
<iframe src="..." frameborder="0" scrolling="no" onload="resizeIframe(this)" />
在站点讨论中找到.
这篇关于不使用滚动条让iframe根据内容自动调整高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文