iframe任何浏览器下自动伸缩

很多朋友都在使用iframe中遇到过不能自动随页面伸缩,特别是动态读取页面的时候,会出现滚动条,影响美观,今天研究一下了,发现了一个简单解决的办法,可以在IE,FIREFOX,OPERA下使用,方法如下,将2段代码照提示保存。
请保存为mainframe.htm

程序代码 程序代码

<html>  
<body>  
<div>  
<iframe marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0"
id="frametb"  scrolling="no" src="frame.htm"  
οnlοad="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语句中修改相对应的调用文件名称和路径,并且注意下面这句:

程序代码 程序代码

οnlοad="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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值