iframe的自适应高度

<iframe src="index.html" id="iframepage" name="iframepage" frameBorder=0 scrolling=no width="100%" onLoad="reinitIframeEND();">
</iframe>
<script type="text/javascript" language="javascript">

function reinitIframe(){
var iframe = document.getElementById("iframepage");
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){}
}

var timer1 = window.setInterval("reinitIframe()", 500); //定时开始

function reinitIframeEND(){
var iframe = document.getElementById("iframepage");
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){}
// 停止定时
window.clearInterval(timer1);

}

上一篇:Excel公式的常见错误值及其解决方法


下一篇:UVA 10003 Cutting Sticks(区间dp)