iframe 自適應(yīng)高度[在IE6 IE7 FF下測試通過]
更新時間:2009年04月13日 10:41:45 作者:
有時候我們需要讓我們的iframe自動適應(yīng)高度,但多瀏覽器兼容性不好,大家不妨試下這個。
第一種方法:
<script type="text/javascript" language="javascript">
<!--
//調(diào)整 PageContent 的高度
function TuneHeight() {
var frm = document.getElementById("content01");
var subWeb = document.frames ? document.frames["content01"].document : frm.contentDocument;
if(frm != null && subWeb != null) {
frm.height = subWeb.body.scrollHeight;
}
}
//-->
</script>
<iframe id="content01" name="content01" frameBorder=0 scrolling=no src="main.html" width="100%"onLoad="TuneHeight()" ></iframe>
第二種方法:
js code:
//iframe自適應(yīng)高度[在IE6 IE7下測試通過]
function reSetIframe(){
var iframe = document.getElementById("iframeId");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
html:
<iframe src="" id="weather" name="weather" width="278" onload="reSetIframe()" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border="0" framespacing="0"> </iframe>
復制代碼 代碼如下:
<script type="text/javascript" language="javascript">
<!--
//調(diào)整 PageContent 的高度
function TuneHeight() {
var frm = document.getElementById("content01");
var subWeb = document.frames ? document.frames["content01"].document : frm.contentDocument;
if(frm != null && subWeb != null) {
frm.height = subWeb.body.scrollHeight;
}
}
//-->
</script>
<iframe id="content01" name="content01" frameBorder=0 scrolling=no src="main.html" width="100%"onLoad="TuneHeight()" ></iframe>
第二種方法:
js code:
復制代碼 代碼如下:
//iframe自適應(yīng)高度[在IE6 IE7下測試通過]
function reSetIframe(){
var iframe = document.getElementById("iframeId");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
html:
復制代碼 代碼如下:
<iframe src="" id="weather" name="weather" width="278" onload="reSetIframe()" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border="0" framespacing="0"> </iframe>
您可能感興趣的文章:
- 關(guān)于div自適應(yīng)高度/左右高度自適應(yīng)一致的js代碼
- Iframe自適應(yīng)高度絕對好使的代碼 兼容IE,遨游,火狐
- Iframe 自適應(yīng)高度并實時監(jiān)控高度變化的js代碼
- javascript 裝載iframe子頁面,自適應(yīng)高度
- iframe自適應(yīng)高度的多種方法方法小結(jié)
- Iframe自適應(yīng)高度兼容ie,firefox多瀏覽器
- 讓iframe自適應(yīng)高度(支持XHTML,支持FF)
- 讓iframe自適應(yīng)高度(支持xhtml)IE firefox兼容
- [轉(zhuǎn)]目前找到的最好的Iframe自適應(yīng)高度代碼
- 關(guān)于IFRAME 自適應(yīng)高度的研究
- JavaScript 處理Iframe自適應(yīng)高度(同或不同域名下)
相關(guān)文章
JavaScript 拖拽與觀察者模式的實現(xiàn)及應(yīng)用小結(jié)
本文通過代碼片段詳細介紹了JavaScript中的拖拽功能和觀察者模式(發(fā)布-訂閱模式)的實現(xiàn)及其應(yīng)用場景,拖拽功能允許用戶通過鼠標移動元素,而觀察者模式則定義了一種一對多的依賴關(guān)系,使得對象能夠自動更新,感興趣的朋友跟隨小編一起看看吧2025-01-01
部分網(wǎng)站允許空白referer的防盜鏈圖片的js破解代碼
主要是有些網(wǎng)站的圖片調(diào)用是防盜鏈的但一般只是判斷referer是不是自己網(wǎng)站,如果referer為空也會顯示圖片,所以有了下面的代碼。2011-05-05
JavaScript 操作table,可以新增行和列并且隔一行換背景色代碼分享
這篇文章介紹了JavaScript操作table,可以新增行和列并且隔一行換背景色代碼,有需要的朋友可以參考一下2013-07-07
JavaScript 使用Ckeditor+Ckfinder文件上傳案例詳解
這篇文章主要介紹了JavaScript 使用Ckeditor+Ckfinder文件上傳案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-08-08

