iframe如何随src的网页(含2个div)高度变化而变化?
在第一个网页, <head> </head> 之间有自动适应页面代码,如下:
<script type= "text/javascript ">
var iframeids=[ "myTestFrameID "]
var iframehide= "yes "
function dyniframesize()
{
var dyniframe=new Array()
for (i=0; i <iframeids.length; i++)
{
if (document.getElementById)
{
//自动调整iframe高度
dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
if (dyniframe[i] && !window.opera)
{
dyniframe[i].style.display= "block "
if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //如果用户的浏览器是NetScape
dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight;
else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //如果用户的浏览器是IE
dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
}
}
if ((document.all || document.getElementById) && iframehide== "no ")
{
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display= "block "
}
}
}
if (window.addEventListener)
window.addEventListener( "load ", dyniframesize, false)
else if (window.attachEvent)
window.attachEvent( "onload ", dyniframesize)
else
window.onload=dyniframesize
</script>
在body有
<IFRAME name=ifm id= "myTestFrameID " onload= "javascript:{dyniframesize( 'myTestFrameID ');} " marginwidth=0 marginheight=0 frameBorder=0 scrolling=no src= "sjjx.htm " width=475> </IFRAME>
在第二个sjjx.htm网页有:
<script type= "text/javascript ">
//more javascript from http://www.smallrain.net
<!-- Begin
var subs_array = new Array( "sub1 ", "sub2 ");// Put the id 's of your hidden divs in this array
function displaySubs(the_sub){
if (document.getElementById(the_sub).style.display== " "){
document.getElementById(the_sub).style.display = "none ";return
}
for (i=0;i <subs_array.length;i++){
var my_sub = document.getElementById(subs_array[i]);
my_sub.style.display = "none ";
}
document.getElementById(the_sub).style.display = " ";
} <