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; 
        } 
    } 

复制代码 代码如下:

复制代码 代码如下:

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;
        }
    }

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;
}
}

[javascript]
function SetIFrameHeight(down) { var Sys = {}; var ua =
navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie
([\d.]+)/)…

 

您可能感兴趣的文章:

  • JS实现iframe自适应高度的方法(兼容IE与FireFox)
  • js实现iframe自动自适应高度的方法
  • jsp页面iframe高度自适应的js代码
  • javascript原生和jquery库实现iframe自适应高度和宽度
  • js控制iframe的高度/宽度让其自适应内容
  • JavaScript
    处理Iframe自适应高度(同或不同域名下)
  • js实现的真正的iframe高度自适应(兼容IE,FF,Opera)
  • JS实现很实用的对联广告代码(可自适应高度)
  • JS实现自适应高度表单文本框的方法
  • Iframe
    自适应高度并实时监控高度变化的js代码
  • JS实现iframe自适应高度的方法示例

代码如下: function SetIFrameHeight(down)
{ var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s =
ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s =…

] function SetIFrameHeight(down) {
var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s =
ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s =
ua.match(/fire…

发表评论

电子邮件地址不会被公开。 必填项已用*标注