兼容多個瀏覽器的自適應iframe尺寸的腳本

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%" οnlοad="SetWinHeightBySelf(this);"></iframe>


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章