兼容多个浏览器的自适应iframe尺寸的脚本

来源:互联网 发布:2016中国粮食浪费数据 编辑:程序博客网 时间:2024/04/30 08:36

JS代码如下:

<script type="text/javascript">    function SetWinHeightBySelf(iframeObj){    if (document.getElementById){       if (iframeObj){        if (iframeObj.contentDocument && iframeObj.contentDocument.body.offsetHeight){          iframeObj.height = iframeObj.contentDocument.body.offsetHeight;          } else if (document.frames[iframeObj.name].document && document.frames[iframeObj.name].document.body.scrollHeight){  iframeObj.height = document.frames[iframeObj.name].document.body.scrollHeight;          }        }      }    }</script>


在页面相应的内嵌框架中使用如下:

<iframe name="frameContent" src="main.html" frameborder="0" width="100%" onload="SetWinHeightBySelf(this);"></iframe>


 

原创粉丝点击