制作iframe占用垂直空间

Ber*_*dan 8 html javascript css iframe

我希望有一个iframe尽可能多的垂直空间,因为它需要显示其内容而不显示滚动条.它可能吗?

有没有解决方法?

cee*_*yoz 10

这应该将IFRAME高度设置为其内容的高度:

<script type="text/javascript">
the_height = document.getElementById('the_iframe').contentWindow.document.body.scrollHeight;
document.getElementById('the_iframe').height = the_height;
</script>
Run Code Online (Sandbox Code Playgroud)

您可能希望添加scrolling="no"到您IFRAME关闭滚动条.

编辑:哎呀,忘了申报the_height.

  • 非常方便,干杯.可能值得一提的是,如果由于相同的原始策略,iframe位于不同的域中,这将无法正常工作 (4认同)