IE FF 兼容的IFRAME 自适应高度JS代码

function SetCwinHeight() {
            var iframeid = document.getElementById("EnterpriseCard"); //iframe id
            if (document.getElementById) {
                if (iframeid && !window.opera) {
                    if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight) {
                        jQuery("#EnterpriseCard").css({ "height": iframeid.contentDocument.body.offsetHeight+20 });
                        iframeid.allowTransparency = "true";
                        alert(iframeid.contentDocument.body.offsetHeight);
                        
                    } else if (iframeid.Document && iframeid.Document.body.scrollHeight) {
                        jQuery("#EnterpriseCard").css({ "height": iframeid.contentDocument.body.offsetHeight + 20 });
                        iframeid.allowTransparency = "true";
                        
                    }
                }
            }
        }

 

如果IFRAME的SRC变化可以用

jQuery().ready(function () {
                    jQuery("#EnterpriseCard").load(function () {
                        SetCwinHeight();
                    });
                });

 

你可能感兴趣的:(IE FF 兼容的IFRAME 自适应高度JS代码)