您好,欢迎访问一九零五行业门户网

js如何判断不同系统的浏览器类型_javascript技巧

复制代码 代码如下:
function env(){
var ua=navigator.useragent.tolowercase();
function check(r){
return r.test(ua);
}
return {
//判断环境,操作系统、浏览器、是否是https连接等
doc : document,
isstrict : doc.compatmode == css1compat ,
isopera : check(/opera/) ,
ischrome : check(/\bchrome\b/) ,
iswebkit : check(/webkit/) ,
issafari : !check(/\bchrome\b/)&& check(/safari/) ,
issafari2 : !check(/\bchrome\b/)&& check(/safari/)&& check(/applewebkit\/4/), // unique to safari 2
issafari3 : !check(/\bchrome\b/)&& check(/safari/)&& check(/version\/3/),
issafari4 : !check(/\bchrome\b/)&& check(/safari/)&& check(/version\/4/),
isie : !check(/opera/) && check(/msie/) ,
isie7 : !check(/opera/) && check(/msie/)&& check(/msie 7/) ,
isie8 : !check(/opera/) && check(/msie/)&& check(/msie 8/) ,
isie6 : !check(/opera/) && check(/msie/)&&!check(/msie 7/)&& !check(/msie 8/),
isgecko : !check(/webkit/)&& check(/gecko/),
isgecko2 : check(/webkit/)&& check(/rv:1\.8/),
isgecko3 : check(/webkit/)&& check(/rv:1\.9/),
isborderbox : !check(/opera/) && check(/msie/)&& doc.compatmode != css1compat,
iswindows : check(/windows|win32/),
ismac : check(/macintosh|mac os x/),
isair : check(/adobeair/),
islinux : check(/linux/),
issecure : /^https/i.test(window.location.protocol),
/**
* 是否为空,如果允许allowblank=true,则当v=''时返回true
*/
isempty : function(v, allowblank){
return v === null || v === undefined || ((this.isarray(v) && !v.length)) || (!allowblank ? v === '' : false);
},
/**
* 是否为数组类型
*/
isarray : function(v){
return tostring.apply(v) === '[object array]';
},
/**
* 是否为日期类型
*/
isdate : function(v){
return tostring.apply(v) === '[object date]';
},
/**
* 是否为object类型
*/
isobject : function(v){
return !!v && object.prototype.tostring.call(v) === '[object object]';
},
/**
* 判断是否是函数
*/
isfunction : function(v){
return tostring.apply(v) === '[object function]';
},
/**
* 判断是否为数字
*/
isnumber : function(v){
return typeof v === 'number' && isfinite(v);
},
/**
* 判断字符串类型
*/
isstring : function(v){
return typeof v === 'string';
},
/**
* 判断布尔类型
*/
isboolean : function(v){
return typeof v === 'boolean';
},
/**
* 判断是否为dom元素
*/
iselement : function(v) {
return !!v && v.tagname;
},
/**
* 判断是否已定义
*/
isdefined : function(v){
return typeof v !== 'undefined';
}
}
然后var env = env(); 用env. 来取的所需的类型。
其它类似信息

推荐信息