在页面无刷新更新方面,虽然如今的ajax很强悍,可是处理代码相对多点。想比之下,iframe就简单多了!处理iframe的自适应宽、高,会常常用到,网上整理了一份,写在这里备用:php
单个iframe 高度自适应:ajax
<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>测试
起做用的是这句:onload="this.height=iFrame1.document.body.scrollHeight"this
多层嵌套iframe 高度自适应:
A页面的iframe:
<iframe id="frame_content" src=”B.php“ name="right" width="1003" frameborder="0" scrolling="no" ></iframe>firefox
B.php页面又有一个iframe:
<iframe width="750" name="rightform" id="rightform" src="KinTimMng_right_init.php" frameborder="0" scrolling="no" onload="this.height=rightform.document.body.scrollHeight;parent.document.getElementById('frame_content').style.height= document.body.scrollHeight + 'px';" ></iframe>orm
起做用的代码是这句:onload="this.height=rightform.document.body.scrollHeight;parent.document.getElementById('frame_content').style.height= document.body.scrollHeight + 'px';"htm
onload的时候执行了两条js语句:get
一、设置当前iframe本身的高度自适应
this.height=rightform.document.body.scrollHeight iframe
二、设置父iframe的高度自适应(注意后面的高度单位px,若是不加单位,firefox下不起做用)
parent.document.getElementById('frame_content').style.height= document.body.scrollHeight + 'px'it
以上代码在ie六、ie七、ie八、firefox3.5下测试经过