Iframe 自適應(yīng)長(zhǎng)度
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";
}
下面為當(dāng)前函數(shù)的變種:
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";
}
使用時(shí),可以直接如此:
<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 閱讀(452) 評(píng)論(0) 編輯 收藏