|
復(fù)制代碼 代碼如下:
<div id="frameBox">
<iframe id="frameWin" src="1.html" name="opWin" style="width:100%; height:100% " frameborder="0" scrolling="no"></iframe>
</div>
3個(gè)菜單鏈接,分別在iframe加載 1.html、2.html、3.html 三個(gè)頁(yè)面。
3個(gè)子頁(yè)面分別在自己頁(yè)面加載完window.onload執(zhí)行
復(fù)制代碼 代碼如下:
function aa(){
var newHeight = document.body.scrollHeight + 20 + "px";
window.parent.document.getElementById("frameBox").style.height = newHeight;
//以上firefox通過(guò),但是ie6必須加上下面這句,不然iframe高度是改了,但是可見(jiàn)區(qū)域沒(méi)有改
window.parent.document.getElementById("frameWin").style.height = newHeight;
}
以下方法只需要把代碼放在主頁(yè)面:
頁(yè)面代碼:
復(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腳本(加在主頁(yè)面):
復(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;
}
JavaScript技術(shù):javascript 裝載iframe子頁(yè)面,自適應(yīng)高度,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。