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

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>


返回顶部
跳到底部

Copyright 2011-2024 南京追名网络科技有限公司 苏ICP备2023031119号-6 乌徒帮 All Rights Reserved Powered by Z-BlogPHP Theme By open开发

请先 登录 再评论,若不是会员请先 注册