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 = " ";
}
// End -->
</script>
<tr>
<TD height=22> <a href= "javascript:void(0) " onClick= "displaySubs( 'sub1 ') " onFocus= "if(this.blur)this.blur() ";>
<b> 基本要求 </b> </a> </TD>
</tr>
<tr>
<TD> <div id= "sub1 " style= "display:none "> aaaaaaaa </div> </TD>
</tr>
<tr>
<TD height=22> <a href= "javascript:void(0) " onClick= "displaySubs( 'sub2 ') " onFocus= "if(this.blur)this.blur() ";>
<b> 学习要点 </b> </a> </TD>
</tr>
<tr>
<TD> <div id= "sub2 " style= "display:none "> aaaaaaaaa </div> </td> <tr>
就这样的代码。我打开第一个网页点击“基本要求“时,出现层的内容。但是sjjx.htm的内容随着层的下拉而整体往下从而高度增加,导致sjjx.htm的内容显示不全,请问高手,该怎么改?谢谢了
[解决办法]
iframe中加入滚动条吧。页面内容就可以显示全了。
scrolling=yes
[解决办法]
加上parent.dyniframesize(); " 就可以了。
<a href= "javascript:void(0) " onClick= "displaySubs( 'sub1 ');parent.dyniframesize(); " ...>