首頁 > web前端 > js教程 > 主體

JavaScript自動設定IFrame高度的小範例_javascript技巧

WBOY
發布: 2016-05-16 17:32:25
原創
1073 人瀏覽過

複製程式碼 程式碼如下:

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 = "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.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 = pTar.contentDocument.body.offsetHeight + 10;
            } else {
                pTar.height = pTar.contentDocument.body.offsetHeight;
            }
            pTar.width = pTar.contentDocument.body.scrollWidth;
        }
    }

function SetIFrameHeight(down) {
        var Sys = {};
              (s = ua.match(/msie ) ) ([d.])/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox/([d.] )/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome/([d.] )/)) ? (/歌劇。([d.])/)) ? Sys.opera = s[1] :
        (s = ua.match(/version/([d.] ).*safari/)) ? Sys.safari = s[1] : 0;
        var pTar = null;
        down);
        } else {
eval('pTar='迭代';');
        }
        pTar.style.display = "block";ptar.height = ptar.contentwindow.document.document.body.offsetheight 15「 px」; ptar.width = ptar.contentwindow.document.document.document.document.body.scroll. scrollwidth「 px」 px';
>} else if (Sys.ie == '8.0') {
              .Document.body.offsetHeight 15 "px";
                pTar.width = pTar.Doc你知道。body.scrollwidth「 px」;
} else {
ptar. width = ptar = ptar.document.document.document.body.scrollwidth「 px」 px';
}
        }
    pTar.height = pTar.contentDocument. body.offsetHeight 15 "px";
            pTar.width = pTar.contentDocu ment.body。 🎜>            pTar.height = pTar .contentDocument.body.offsetHeight;
            pTar.width = pTar.contentDocument.body.scrollWidth;             pTar.height = pTar.contentDocument.body.offsetHeight ;
            pTar.width = pTar.contentDocument.body.scrollWidth;
             if (pTar.contentDocument.body.offsetHeight                 pTar.height = pTar.contentDocument.body.offsetHeight 10;
         pTar .height = pTar.contentDocument.body.offsetHeight;
            }
     .body.scrollWidth;
        }
    }



相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!