获得iframe 高度 ,各种浏览器

function  fuFunctiondan(){
    var frm=$("#z_div");
            var iframeHeight=0;
            if (navigator.userAgent.indexOf("Firefox")>0) { // Mozilla, Safari, ...  
                iframeHeight=window.frames[0].document.body.scrollHeight;
                alert(iframeHeight);
                iframeHeight=parseInt(iframeHeight)+0;
                frm.height(iframeHeight);
                $("#MainFrame").height(iframeHeight);
            } else if (navigator.userAgent.indexOf("MSIE")>0) { // IE  
                iframeHeight=MainFrame.document.body.scrollHeight;//IE这里要用,不能用obj,切记  
                iframeHeight=parseInt(iframeHeight)+parseInt(0);
                frm.height(iframeHeight);
                $("#MainFrame").height(iframeHeight);
            }else {
                 iframeHeight=MainFrame.document.body.scrollHeight;
                 iframeHeight=parseInt(iframeHeight)+0;
                 frm.height(iframeHeight);
                 $("#MainFrame").height(iframeHeight);
            }
}
z_div为iframe 外层div 的id,
MainFrame为iframe 的id ;


原文地址:https://www.cnblogs.com/zhangchenglzhao/p/3144512.html