iframe自动适应其内src中内容大小

在使用TreeView控件时,我习惯使用iFrame包含TreeView节点导航到的页面(其它的方式没试过)。
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
                        
<tr>
                            
<td rowspan="1" style="width: 15%" valign="top">
                                
<asp:TreeView ID="TreeRegion" runat="server" ShowLines="True">
                                    
<SelectedNodeStyle Font-Bold="True" />
                                
</asp:TreeView>
                            
</td>
                            
<td rowspan="1" style="width: 80%" valign="top">
                                
<iframe name="ClientInfoList" src="ClientInfoList.aspx" frameborder="0"
                                    width
="100%"></iframe>
                            
</td>
                        
</tr>
                    
</table>
如果ClientInfoList.aspx页面比较大,就会有滚动条出现,很不好看。可以考虑使用iFrame自动适应所包含的页面大小,代码如下:
<script language="javascript">
function BodyOnLoad(){
if (window != top)//如果这个页面是被包含的,就执行下面的代码
window.resizeTo(window.document.body.scrollWidth, window.document.body.scrollHeight);
}

}

</script>

<body onload = "BodyOnLoad()">
posted @ 2006-11-28 09:39  Rechro  阅读(1027)  评论(1编辑  收藏  举报