>웹 프론트엔드 >JS 튜토리얼 >JavaScript는 자동으로 IFrame 높이를 설정합니다.

JavaScript는 자동으로 IFrame 높이를 설정합니다.

高洛峰
高洛峰원래의
2016-11-28 11:10:081111검색

[javascript]
function SetIFrameHeight(down) { 
        var Sys = {}; 
        var ua = navigator.userAgent.toLowerCase(); 
        var s; 
        (s = ua.match(/msie ([d.]+)/)) ? Sys.ie = s[1] : 
        (s = ua.match(/firefox/([d.]+)/)) ? Sys.firefox = s[1] : 
        (s = ua.match(/chrome/([d.]+)/)) ? Sys.chrome = s[1] : 
        (s = ua.match(/opera.([d.]+)/)) ? Sys.opera = s[1] : 
        (s = ua.match(/version/([d.]+).*safari/)) ? Sys.safari = s[1] : 0; 
        var pTar = null; 
        if (document.getElementById) { 
            pTar = document.getElementById(down); 
        } else { 
            eval('pTar=' + down + ';'); 
        } 
        pTar.style.display = "차단"; 
        if (Sys.ie) { 
            if (Sys.ie == '9.0') { 
               pTar.height = pTar.contentWindow.document.body.offsetHeight + 15 + "px"; 
                pTar.width = pTar.contentWindow.document.body.scrollWidth + "px"; 
            } else if (Sys.ie == '8.0') { 
                디버거; 
                pTar.height = pTar.Document.body.offsetHeight + 15 + "px"; 
                pTar.width = pTar.Document.body.scrollWidth + "px"; 
            } else { 
                pTar.height = pTar.Document.body.scrollHeight + 25 + "px"; 
                pTar.width = pTar.Document.body.scrollWidth + "px"; 
            } 
        } 
        if (Sys.firefox) { 
            pTar.height = pTar.contentDocument.body.offsetHeight + 15 + "px"; 
            pTar.width = pTar.contentDocument.body.scrollWidth + "px"; 
        } 
        if (Sys.chrome) { 
            pTar.height = pTar.contentDocument.body.offsetHeight; 
            pTar.width = pTar.contentDocument.body.scrollWidth; 
        } 
        if (Sys.opera) { 
            pTar.height = pTar.contentDocument.body.offsetHeight; 
            pTar.width = pTar.contentDocument.body.scrollWidth; 
        } 
        if (Sys.safari) { 
            if (pTar.contentDocument.body.offsetHeight <= '186') { 
               pTar.height = .body.offsetHeight + 10 ; 
            } else { 
                pTar.height = pTar.contentDocument.body.offsetHeight; 
            } 
            pTar.width = pTar.contentDocument.body.scrollWidth; 
        } 
    } 

함수 SetIFrameHeight(down) {
        var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox/([d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome/([d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version/([d.]+).*safari/)) ? Sys.safari = s[1] : 0;
        var pTar = null;
        if (document.getElementById) {
            pTar = document.getElementById(down);
        } else {
eval('pTar=' + down + ';');
        }
        pTar.style.display = "block";
        if (Sys.ie) {
            if (Sys.ie = = '9.0') {
               pTar.height = pTar.contentWindow.document.body.offsetHeight + 15 + "px";
               pTar.width = pTar.contentWindow.document.body.scrollWidth + "px";
            } else if (Sys.ie == '8.0') {
               debugger;
               pTar.height = pTar.Document.body.offsetHeight + 15 + "px";
                pTar.width = pTar.Document.body.scrollWidth + "px";
            } else {
               pTar.height = pTar.Document.body.scrollHeight + 25 + "px";
               pTar.width = pTar. 문서. body.scrollWidth + "px";
            }
        }
        if (Sys.firefox) {
           pTar.height = pTar.contentDocument.body.offsetHeight + 15 + "px";
pTar.width = pTar.contentDocument.body.scrollWidth + "px";
        }
        if (Sys.chrome) {
           pTar.height = pTar.contentDocument.body.offsetHeight;
            pT 아르. width = pTar.contentDocument.body.scrollWidth;
        }
        if (Sys.opera) {
           pTar.height = pTar.contentDocument.body.offsetHeight;
            pTar.width = pTar .content문서. body.scrollWidth;
        }
        if (Sys.safari) {
            if (pTar.contentDocument.body.offsetHeight <= '186') {
               pTar.height = pTar .contentDocument.body .offsetHeight + 10;
            } else {
               pTar.height = pTar.contentDocument.body.offsetHeight;
           }
           pTar.width = pTar.content Document.body.scrollWidth;
        }
    }


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.