DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JavaScript自動設置IFrame高度的小例子
JavaScript自動設置IFrame高度的小例子
編輯:關於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 = "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 = {};
        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;
        }
    }

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved