http://blog.sina.com.cn/yangedie[订阅]
字体大小: 正文
让iframe自适应高度 改进(2008-06-13 00:23:58)

上一篇文章《让iframe自适应高度》有两个缺点:

  • 每一个嵌进来的页面都要去修改(如果有50个页面,那工作量可就大了)
  • 占用了每一个嵌进来的页面的onload

修改了一下,把函数放在了主页面,这样只修改一个页面就ok了。

ie6、firefox2 通过,希望ie7的网友帮忙测试
主页面代码:


<div style="border:1px solid #7e99c6" id="frameBox">
<iframe id="frameWin" src="01.html" name="opWin" style="width:100%; height:100% " frameborder="0" scrolling="no" onload="changeSize()"></iframe>
</div>
js脚本(加在主页面):

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;
}
  • 评论加载中,请稍候...
发评论    明星私家相册

验证码:看不清楚数字吗?点击这里再试试。收听验证码

发评论

以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

相关博文
读取中...
推荐博文
读取中...