zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JS浏览器系统 如何 类型 判断 不同
2023-06-13 09:15:07 时间
复制代码代码如下:

functionEnv(){
varua=navigator.userAgent.toLowerCase();
functioncheck(r){
returnr.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/),//uniquetoSafari2
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(/msie7/),
isIE8:!check(/opera/)&&check(/msie/)&&check(/msie8/),
isIE6:!check(/opera/)&&check(/msie/)&&!check(/msie7/)&&!check(/msie8/),
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|macosx/),
isAir:check(/adobeair/),
isLinux:check(/linux/),
isSecure:/^https/i.test(window.location.protocol),
/**
*是否为空,如果允许allowBlank=true,则当v=""时返回true
*/
isEmpty:function(v,allowBlank){
returnv===null||v===undefined||((this.isArray(v)&&!v.length))||(!allowBlank?v==="":false);
},

/**
*是否为数组类型
*/
isArray:function(v){
returntoString.apply(v)==="[objectArray]";
},

/**
*是否为日期类型
*/
isDate:function(v){
returntoString.apply(v)==="[objectDate]";
},

/**
*是否为Object类型
*/
isObject:function(v){
return!!v&&Object.prototype.toString.call(v)==="[objectObject]";
},

/**
*判断是否是函数
*/
isFunction:function(v){
returntoString.apply(v)==="[objectFunction]";
},

/**
*判断是否为数字
*/
isNumber:function(v){
returntypeofv==="number"&&isFinite(v);
},

/**
*判断字符串类型
*/
isString:function(v){
returntypeofv==="string";
},

/**
*判断布尔类型
*/
isBoolean:function(v){
returntypeofv==="boolean";
},

/**
*判断是否为dom元素
*/
isElement:function(v){
return!!v&&v.tagName;
},

/**
*判断是否已定义
*/
isDefined:function(v){
returntypeofv!=="undefined";
}
}

然后varenv=env();用env.来取的所需的类型。