关于有ajax 请求的iframe自适应高度问题

关于第一种iframe自适应高度问题比较简单

页面加载完后 重新计算一下高度

1 document.onreadystatechange=function() {  
2           if(document.readyState=="complete"){
3            window.parent.document.getElementById("iframeID").height=document.body.scrollHeight;
4               }  
5     }

还有一种就是页面有使用jQuery ajax请求,页面加载完后,请求还在继续,页面的高度还在改变

这种使用上面的方法完全实现不了效果

第二种 使用jquery的 ajaxComplete 方法,每一次ajax 请求完成后,都再次获取页面高度更改iframe 高度

    function getheightouat(){
                window.parent.document.getElementById("iframeID").height=document.body.scrollHeight;
    }
    $(document).ajaxStart(function(){})
    .ajaxComplete(function(){
        getheightouat();
    }).ajaxStop(function(){});
原文地址:https://www.cnblogs.com/yehshuai/p/4210111.html