欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 裝載iframe子頁面,自適應(yīng)高度

 更新時間:2009年03月20日 23:14:55   作者:  
javascript 裝載iframe子頁面,自適應(yīng)高度
假設(shè)主頁面有一個div,里面放置一個iframe
復(fù)制代碼 代碼如下:

<div id="frameBox">
<iframe id="frameWin" src="1.html" name="opWin" style="width:100%; height:100% " frameborder="0" scrolling="no"></iframe>
</div>

3個菜單鏈接,分別在iframe加載 1.html、2.html、3.html 三個頁面。

3個子頁面分別在自己頁面加載完window.onload執(zhí)行
復(fù)制代碼 代碼如下:

function aa(){
var newHeight = document.body.scrollHeight + 20 + "px";
window.parent.document.getElementById("frameBox").style.height = newHeight;
//以上firefox通過,但是ie6必須加上下面這句,不然iframe高度是改了,但是可見區(qū)域沒有改
window.parent.document.getElementById("frameWin").style.height = newHeight;
}

以下方法只需要把代碼放在主頁面:
頁面代碼:
復(fù)制代碼 代碼如下:

<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="test2()"></iframe>
</div>

js腳本(加在主頁面):
復(fù)制代碼 代碼如下:

function test2(){
var frameWin = document.getElementById("frameWin");
var frameBox = document.getElementById("frameBox");
var newHeight;
if (frameWin.Document){
newHeight = frameWin.Document.body.scrollHeight + 20 + "px";
}else{
newHeight = frameWin.contentDocument.body.scrollHeight+ 20 + "px";
}
frameWin.style.height = newHeight;
frameBox.style.height = newHeight;
}

相關(guān)文章

最新評論