让iframe框架网页在任何浏览器下自动伸缩


  本文标签:iframe,自动伸缩

步骤如下,将2段代
码照 揭示 保留 。
请 保留为mainframe.htm
复制代码 代码如下:

<html> 
<body> 
<div> 
<iframe marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" 
id="frametb" scrolling="no" src="frame.htm" 
onload="style.width=this.contentWindow.document.all.formfra.offsetWidth;"
+"style.height=this.contentWindow.document.all.formfra.offsetHeight"></iframe> 
</div> 
</body> 
</html>

请 保留为frame.htm
复制代码 代码如下:

<html> 
<body leftmargin="0" topmargin="0"> 
<table id=formfra width=200 border=0 bgcolor=green> 
<tr><td> 
胡东平在线空间
<p/>
sfsfere 
</td></tr> 
</table> 
</body> 
</html>


执行mainframe.htm就 可以看到 动机了 。
套用 批改的时候要 留神mainframe.htm和frame.htm里面定义表格的ID, 而后记得在frame语句中 批改 绝对应的
调用文件名称和路径,而且 留神下面这句:
复制代码 代码如下:

onload="style.width=this.contentWindow.document.all.formfra.offsetWidth;"
+"style.height=this.contentWindow.document.all.formfra.offsetHeight"

做相应 批改
复制代码 代码如下:

this.contentWindow.document.all.调用页面表格ID.offsetWidth
this.contentWindow.document.all.调用页面表格ID.offsetHeight

记住, 定然要定义表格ID 。