iframe 自适应高度,多层嵌套iframe自适应高度

一、单个iframe 高度自适应
<iframe src="yx/yx_list.html" width="100%" [color=red]onload[/color]="[color=blue]this.height=this.contentWindow.document.body.scrollHeight[/color]" scrolling="no" name="rtFrame" frameborder="0"></iframe>


当前窗口自适应高度:this.height=this.contentWindow.document.body.scrollHeight

子窗体窗口自适应高度:
window.parent.document.getElementById("rtFrame").height=document.body.scrollHeight;


二、多层嵌套iframe 高度自适应
A页面的iframe 加载B.html文件:
<iframe id="frame_content" src=”B.html“ name="right" width="1003" frameborder="0" scrolling="no" ></iframe>

B.html页面也有一个iframe:
<iframe width="750" name="rightform" id="rightform" src="KinTimMng_right_init.php" frameborder="0" scrolling="no" [color=blue]οnlοad="this.height=this.contentWindow.document.body.scrollHeight;parent.document.getElementById('frame_content').style.height= document.body.scrollHeight + 'px';"[/color] ></iframe>


onload的时候执行了两条js语句

1、设置当前iframe自己的高度自适应
this.height=rightform.document.body.scrollHeight

2、设置父iframe的高度自适应(注意后面的高度单位px,如果不加单位,firefox下不起作用)
parent.document.getElementById('frame_content').style.height= document.body.scrollHeight + 'px'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值