iframe 自适应高度[在IE6 IE7 FF下测试通过]

(编辑:jimmy 日期: 2024/10/9 浏览:2)

第一种方法:
复制代码 代码如下:
<script type="text/javascript" language="javascript">
<!--
//调整 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="/UploadFiles/2021-04-02/main.html">
第二种方法:
js code:
复制代码 代码如下:
//iframe自适应高度[在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="/UploadFiles/2021-04-02/">