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>