iframe自适应高度(适应ie7和firefox)
iframe 高度自适应
编者按:我们在设计潮汕风情网的时候,把评论设计在一个动态页面中,通过iframe嵌套进新闻页面里面。由于评论可能有1条,也可能有5条,并且评论字数也不相同,所以有必要让iframe的高度自适应,不然设置高度不够,就会遮住下面部分,设置高度太高,就会产生大片空白。下面这段js代码可以很好的兼容ie7和firefox浏览器,推荐使用。
<script type="text/javascript" language="javascript">
<!--
//调整 PageContent 的高度
function TuneHeight()
{
var frm = document.getElementById("FM_Content");
var subWeb = document.frames ? document.frames["FM_Name"].document : frm.contentDocument;
if(frm != null && subWeb != null)
{ frm.height = subWeb.body.scrollHeight;}
}
//-->
</script>
<iframe id="FM_Content" name="FM_Name" frameborder="0" height="530px" width="780px" src="Corporate/CorporateList.aspx" onLoad="TuneHeight()" scrolling="no">
</iframe>
来源:http://www.firefox.net.cn/newforum/viewtopic.php?p=144268