聂永的博客

记录工作/学习的点点滴滴。

Iframe 自适应长度

function initIframeSize(){
var frameID = "frameID";
var bodyIFrame = document.getElementById(frameID);
var minLen = 550;
var height = -1;
try{
height = window.frames[frameID].document.body.scrollHeight;
}catch(e){
//可以兼容Firefox
height = bodyIFrame.contentDocument.body.scrollHeight;
}
if( height < minLen )height = minLen;
bodyIFrame.style.height = height + "px";
}
下面为当前函数的变种:
function initIframeSize(frameID){
var bodyIFrame = document.getElementById(frameID);
var minLen = 550;
var height = -1;
try{
height = window.frames[frameID].document.body.scrollHeight;
}catch(e){
//可以兼容Firefox
height = bodyIFrame.contentDocument.body.scrollHeight + 20;
}
if( height < minLen )height = minLen;
bodyIFrame.style.height = height + "px";
}
使用时,可以直接如此:
<iframe src="proBoxContent.htm" frameborder="0" width="100%" height="100%" id="frameIDs" onload="initIframeSize(this.id)"></iframe>

posted on 2008-12-29 15:38 nieyong 阅读(444) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

公告

所有文章皆为原创,若转载请标明出处,谢谢~

新浪微博,欢迎关注:

导航

<2008年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

统计

常用链接

留言簿(58)

随笔分类(130)

随笔档案(151)

个人收藏

最新随笔

搜索

最新评论

阅读排行榜

评论排行榜