body 适应ifram 高度

<!--Iframe自适应其加载的内容高度-->
<script type="text/javascript">
     function iframeAutoFit()
     {
        try
        {
           if(window!=parent)
           {
            var a = parent.document.getElementsByTagName("IFRAME");
              for(var i=0; i<a.length; i++) //author:meizz
              {
                 if(a[i].contentWindow==window)
                 {
                     var h = document.body.scrollHeight;
                     if(document.all) {h += 4;}
                     if(window.opera) {h += 1;}
                     a[i].style.height = h;
                 }
              }
           }
        }
        catch (ex)
        {
           alert("脚本无法跨域操作!");
        }
     }
     if(document.attachEvent)    window.attachEvent("onload",    iframeAutoFit); 
     else    window.addEventListener('load',    iframeAutoFit,    false); 
</script> 

function my_init()
{

minHeight = document.getElementById("listWindow").offsetHeight;
minWidth = document.getElementById("listWindow").offsetWidth;

}

function resizeHeight(h, w)
{
    h += 40;
//    if (w) {w += 20;}
    if (h>minHeight) {document.all.listWindow.style.height = h;}
    if (w && w>minWidth) {document.all.listWindow.style.width = w;}
//    if (parent && parent.resizeHeight) {parent.resizeHeight(document.body.scrollHeight);}
}

ifram 页面

function my_init()
{

if (parent && parent.resizeHeight) {parent.resizeHeight(document.body.scrollHeight);}

}

原文地址:https://www.cnblogs.com/xsmhero/p/1860550.html