今天下午,为了这个“小”问题,研究了半天,搜了半天,不过,现在网上的都是抄来抄去,试了十几种方案都不行,最后呢,还是搞定了,所以,赶紧写下来,备忘用吧!
网上找了很多文章,常见的如:
<iframe src="right1.html" name="mainFrame" id="mainFrame" width="740px" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementByIdx_x("mainFrame");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 200);
</script>
但是测试发现,在火狐下,并不能收缩。需要刷新页面。
下面方法解决问题:
<iframe id="mainFrame" name="mainFrame" width="100%" οnlοad="this.height=mainFrame.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
测试浏览器:IE6、IE7、IE8、FF3.0