我的网页index.html里有一个iframe,通过以下代码实现了高度自适应,
<iframe name="ifrm" id="ifrm" src="main.html" width="100%" onload="this.height=ifrm.document.body.scrollHeight" scrolling="no" align="middle" frameborder="0"> </iframe>然后我在main.html文件里有一个tab表格,通过以下代码控制显示的内容<script>
<!--
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
var newHeight = document.body.scrollHeight + 20 + "px";
window.parent.document.getElementById("ifrm").style.height = newHeight;
}
//-->
其中加粗的两行是用来实现当点击一个tab时,iframe高度自适应,这一部分也成功了但是问题来了: 当使用了setTab 函数自适应高度后,再点击index.html里的链接切换iframe内容时,自适应高度就失效了,始终保持tab的高度,不能切换到其他网页的高度了。这是为什么?怎么解决?出现问题的网址是http://www.youbeiou.com/index_test.html
<iframe name="ifrm" id="ifrm" src="main.html" width="100%" onload="this.height=ifrm.document.body.scrollHeight" scrolling="no" align="middle" frameborder="0"> </iframe>然后我在main.html文件里有一个tab表格,通过以下代码控制显示的内容<script>
<!--
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
var newHeight = document.body.scrollHeight + 20 + "px";
window.parent.document.getElementById("ifrm").style.height = newHeight;
}
//-->
其中加粗的两行是用来实现当点击一个tab时,iframe高度自适应,这一部分也成功了但是问题来了: 当使用了setTab 函数自适应高度后,再点击index.html里的链接切换iframe内容时,自适应高度就失效了,始终保持tab的高度,不能切换到其他网页的高度了。这是为什么?怎么解决?出现问题的网址是http://www.youbeiou.com/index_test.html
最外层的应该是没问题的...
<table id="mainwidth">
<tr>
<td id="mainview" >
<iframe src=" filmByChannel.jsp?channelindex=<%=request.getParameter("channelindex")%>" width="100%" height="100%" name="main" scrolling="no" border="0" frameborder="0">
这里是内框架,如果看不到请升级你的IE。</iframe></td>
</tr>
</table>
<script language="JavaScript" for="main" event="onload"> <!--本页面加载时动态改变iframe高度-->
mainview.height=main.document.body.scrollHeight+10;
mainwidth.width=main.document.body.scrollWidth+10;
//mainview.width=main.document.body.scrollWidth+10;
</script>
内部没有框架,就一个框架,只是iframe内部的页面里有一个javascript控制的tab表格
可以到我提供的地址上去看看就清楚了。http://www.youbeiou.com/index_test.html
1楼的同志: 什么类型转换问题?能说具体点么?谢谢
5楼的同志: position = 'absolute';在哪里添加,我在iframe所在的div测试了一下,不行
这个问题很妖怪啊,我DOM基础不行,还麻烦各位高手帮我解决一下,谢了先
<div id="Layer1">
<div id="left_navigator">
<p class="listclass"><a href="Destination_main.html" target="destination_frame">目的地列表:</a></p>
<p class="listclass"><a href="destination/stockholm.html" target="destination_frame">- 斯德哥尔摩</a></p>
<p class="listclass"><a href="destination/helsinki.html" target="destination_frame">- 赫尔辛基</a> </p>
<p class="listclass"><a href="destination/gotland.html" target="destination_frame">- 哥特兰岛</a></p>
<p class="listclass"><a href="destination/turku.html" target="destination_frame">- 图尔库</a> </p>
<p class="listclass"><a href="destination/tallin.html" target="destination_frame">- 塔林</a></p>
<p class="listclass"><a href="destination/riga.html" target="destination_frame">- 里加</a> </p>
<p class="listclass"></p>
<p></p>
</div>
<div id="right_frame">
<iframe name="destination_frame" id="destination_frame" src="Destination_main.html" height="410px" width="100%" scrolling="yes" align="left" frameborder="0"> </iframe>
</div>
</div>
因为onload是在页面完全loaded的时候触发的.
如果网速太慢就会有延误的情况.
又或者你某个JS出错也会导致自动调节终止.
改成window.parent.document.getElementById("ifrm").height = newHeight;
试试不加style