JS实现iframe自适应高度的方法示例

原创 2017-01-14 13:12:58 297
摘要:本文实例讲述了JS实现iframe自适应高度的方法。<iframe id="mainFrame" name="mainFrame" src="/zwgk/hsearchview" width="740" frameborder="0" 

本文实例讲述了JS实现iframe自适应高度的方法。

<iframe id="mainFrame" name="mainFrame" src="/zwgk/hsearchview" width="740" frameborder="0" scrolling="no" scrolling="no" frameborder="0" >
</iframe>
<script type="text/javascript" language="javascript">
function reinitIframe(){
 var iframe = document.getElementById("mainFrame");
 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.setInterval("reinitIframe()", 100);
</script>

 更多关于JS实现iframe自适应高度的方法示例请关注PHP中文网(www.php.cn)其他文章!   


发布手记

热门词条