讓iframe框架網(wǎng)頁在任何瀏覽器下自動伸縮
更新時間:2006年08月18日 00:00:00 作者:
很多朋友都在使用iframe中遇到過不能自動隨頁面伸縮,特別是動態(tài)讀取頁面的時候,會出現(xiàn)滾動條,影響美觀,今天研究一下了,發(fā)現(xiàn)了一個簡單解決的辦法,可以在IE,F(xiàn)IREFOX,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"
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>
執(zhí)行mainframe.htm就可以看到效果了。
套用修改的時候要注意mainframe.htm和frame.htm里面定義表格的ID,然后記得在frame語句中修改相對應(yīng)的
調(diào)用文件名稱和路徑,并且注意下面這句:
onload="style.width=this.contentWindow.document.all.formfra.offsetWidth;"
+"style.height=this.contentWindow.document.all.formfra.offsetHeight"
做相應(yīng)修改
this.contentWindow.document.all.調(diào)用頁面表格ID.offsetWidth
this.contentWindow.document.all.調(diào)用頁面表格ID.offsetHeight
記住,一定要定義表格ID。
碼照提示保存。
請保存為mainframe.htm
復(fù)制代碼 代碼如下:
<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
復(fù)制代碼 代碼如下:
<html>
<body leftmargin="0" topmargin="0">
<table id=formfra width=200 border=0 bgcolor=green>
<tr><td>
胡東平在線空間
<p/>
sfsfere
</td></tr>
</table>
</body>
</html>
執(zhí)行mainframe.htm就可以看到效果了。
套用修改的時候要注意mainframe.htm和frame.htm里面定義表格的ID,然后記得在frame語句中修改相對應(yīng)的
調(diào)用文件名稱和路徑,并且注意下面這句:
復(fù)制代碼 代碼如下:
onload="style.width=this.contentWindow.document.all.formfra.offsetWidth;"
+"style.height=this.contentWindow.document.all.formfra.offsetHeight"
做相應(yīng)修改
復(fù)制代碼 代碼如下:
this.contentWindow.document.all.調(diào)用頁面表格ID.offsetWidth
this.contentWindow.document.all.調(diào)用頁面表格ID.offsetHeight
記住,一定要定義表格ID。
相關(guān)文章
javascript使用shift+click實現(xiàn)選擇和反選checkbox的方法
這篇文章主要介紹了javascript使用shift+click實現(xiàn)選擇和反選checkbox的方法,涉及javascript針對鍵盤按鍵的判斷及checkbox的操作技巧,需要的朋友可以參考下2015-05-05JavaScript中解決多瀏覽器兼容性23個問題的快速解決方法
下面小編就為大家?guī)硪黄狫avaScript中解決多瀏覽器兼容性23個問題的快速解決方法。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05Javascript中扁平化數(shù)據(jù)結(jié)構(gòu)與JSON樹形結(jié)構(gòu)轉(zhuǎn)換詳解
之前朋友問過我一個問題,項目中遇到扁平化數(shù)據(jù)結(jié)構(gòu)不知如何樹形化,下面這篇文章主要給大家介紹了關(guān)于Javascript中扁平化數(shù)據(jù)結(jié)構(gòu)與JSON樹形結(jié)構(gòu)轉(zhuǎn)換的相關(guān)資料,需要的朋友可以參考下2022-05-05