上一篇文章《让iframe自适应高度》有两个缺点:
- 每一个嵌进来的页面都要去修改(如果有50个页面,那工作量可就大了)
- 占用了每一个嵌进来的页面的onload
修改了一下,把函数放在了主页面,这样只修改一个页面就ok了。
ie6、firefox2
通过,希望ie7的网友帮忙测试
主页面代码:
<div style="border:1px solid #7e99c6" id="frameBox">js脚本(加在主页面):
<iframe id="frameWin" src="01.html" name="opWin" style="width:100%; height:100% " frameborder="0" scrolling="no" onload="changeSize()"></iframe>
</div>
function changeSize(){
var frameWin = document.getElementById("frameWin");
var frameBox = document.getElementById("frameBox");
var newHeight = frameWin.contentWindow.document.body.scrollHeight + 20 + "px";
frameWin.style.height = newHeight;
frameBox.style.height = newHeight;
}
插入表情