让iframe根据内容自动调整高度而不使用滚动条? [英] Make iframe automatically adjust height according to the contents without using scrollbar?

查看:103
本文介绍了让iframe根据内容自动调整高度而不使用滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

 < iframe name =Stacksrc =http://stackoverflow.com/ width =740
frameborder =0scrolling =noid =iframe> ...
< / iframe>

我希望它能够根据其中的内容调整其高度,而不使用滚动。

 < script> 
function resizeIframe(obj){
obj.style.height = obj.contentWindow.document.body.scrollHeight +'px';
}
< / script>

然后将您的iframe更改为:

 < iframe src =...frameborder =0scrolling =noonload =resizeIframe(this)/> 

sitepoint discussion


For example:

<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.body.scrollHeight + 'px';
  }
</script>

And change your iframe to this:

<iframe src="..." frameborder="0" scrolling="no" onload="resizeIframe(this)" />

As found on sitepoint discussion.

这篇关于让iframe根据内容自动调整高度而不使用滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆