js浏览器信息获取

/*
 * Namespace : com.uk.silence.window
 * Class: Geometry
 * Version : 1.0
 */


var namespace = Module.createNamespace("com.uk.silence.window", 1.0);


namespace.Geometry = (function() {

//浏览器窗口大小及坐上角位置
var Browser = function() {

/*
* 获取浏览器所在位置:
* screenX和screenY需先判断,再判断screenLeft和screenTop
* 原因:在IE9中同时提供screenX,screenY,screenLeft,screenTop.screenX和screenY表示浏览器左上角相对屏幕坐标,screenLeft和screenTop表示浏览器视图区左上角相对屏幕坐标
* IE6,7,8只提供screenLeft和screenTop
* Firefox只提供screenX和screenY
* 在chrome中同时提供screenX,screenY,screenLeft,都表示浏览器左上角相对屏幕坐标

* 获取浏览器大小
* IE9,firefox,chrome中提供outerWidth和outerHeight

*/
var width = 0, height = 0, left =0, top = 0;

if(window.outerWidth) {
width = window.outerWidth;
height = window.outerHeight;
}

if(window.screenX) {
left = window.screenX;
top = window.screenY;
} else if(window.screenLeft) {
left = window.screenLeft;
top = window.screenTop;
}

return {
"width" : width,
"height" : height,
"position" : {
"left" : left,
"top" : left
}
};
};

//浏览器可视区大小
var Viewport = function(){
var width = 0, height = 0, horizontalScroll = 0, verticalScroll = 0;
if(window.innerWidth) {
width = window.innerWidth;
height = window.innerHeight;
horizontalScroll = window.pageXOffset;
verticalScroll = window.pageYOffset;
} else if(document.documentElement && document.documentElement.clientWidth) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
horizontalScroll = document.documentElement.scrollLeft;
verticalScroll = document.documentElement.scrollTop;
} else if(document.body && document.body.clientWidth) {
width = document.body.clientWidth;
height = document.body.clientHeight;
horizontalScroll = document.body.scrollLeft;
verticalScroll = document.body.scrollTop;
}
return {
"width" : width,
"height" : height,
"horizontalScroll" : horizontalScroll,
"verticalScroll" : verticalScroll
};
};

//获取文档大小
var Document = function() {
var width = 0, height = 0;
if(document.documentElement && document.documentElement.scrollWidth) {
width = document.documentElement.scrollWidth;
height = document.documentElement.scrollHeight;
} else if(document.body && document.body.scrollWidth) {
width = document.body.scrollWidth;
height = document.body.scrollHeight;
}
return {
"width" : width,
"height" : height
};
};

//获取滚动条宽度
var Scroll = function() {
var outer = document.createElement("div"),
inner = document.createElement("div"),
barSize = 0;

outer.style.position = "absolute";
outer.style.top = "-1000px";
outer.style.left = "-1000px";
outer.style.width = "100px";
outer.style.height = "100px";
outer.style.margin = "0px";
outer.style.padding = "0px";
outer.style.overflow = "scroll";

document.documentElement.appendChild(outer);

inner.style.position = "relation";
inner.style.border = "0px";
inner.style.height = "200px";
inner.style.margin = "0px";
inner.style.padding = "0px";
outer.appendChild(inner);

barSize = 100 - inner.offsetWidth;

document.documentElement.removeChild(outer);
return {
"barSize" : barSize
};
};
return {
"Browser" : Browser,
"Viewport" : Viewport,
"Document" : Document,
"Scroll" : Scroll
};
})();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值