Home > Web Front-end > JS Tutorial > How does js determine the browser type of different systems_javascript skills

How does js determine the browser type of different systems_javascript skills

WBOY
Release: 2016-05-16 17:18:30
Original
1494 people have browsed it
Copy code The code is as follows:

function Env(){
var ua=navigator.userAgent. toLowerCase();
function check(r){
return r.test(ua);
}
return {
//Determine the environment, operating system, browser, and whether it is https Connection, etc.
DOC: document,
isStrict: DOC.compatMode == "CSS1Compat",
isOpera: check(/opera/),
isChrome: check(/bchromeb/),
isWebKit : check(/webkit/) ,
isSafari : !check(/bchromeb/)&& check(/safari/) ,
isSafari2 : !check(/bchromeb/)&& check(/safari/)&& check (/applewebkit/4/), // unique to Safari 2
isSafari3 : !check(/bchromeb/)&& check(/safari/)&& check(/version/3/),
isSafari4 : !check (/bchromeb/)&& 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) ,
/**
* Whether it is empty, if allowBlank=true is allowed, then true is returned when v=''
*/
isEmpty : function(v, allowBlank){
return v === null || v === undefined || ((this.isArray(v) && !v.length)) || (!allowBlank ? v === '' : false);
},

/**
* Whether it is an array type
*/
isArray : function(v ){
return toString.apply(v) === '[object Array]';
},

/**
* Whether it is date type
*/
isDate : function(v) {
return toString.apply(v) === '[object Date]';
},

/**
* Whether it is Object type
*/
isObject : function(v){
return !!v && Object.prototype.toString.call(v) === '[object Object]';
},

/**
* Determine whether it is a function
*/
isFunction : function(v){
return toString.apply(v) === '[object Function]';
},

/**
* Determine whether it is a number
*/
isNumber : function(v){
return typeof v === 'number' && isFinite(v);
},

/**
* Determine string type
*/
isString : function( v){
return typeof v === 'string';
},

/**
* Determine Boolean type
*/
isBoolean : function(v){
return typeof v === 'boolean';
},

/**
* Determine whether it is a dom element
*/
isElement : function(v) {
return !!v && v.tagName;
},

/**
* Determine whether it has been defined
*/
isDefined : function(v){
return typeof v !== 'undefined';
}
}

Then var env = env(); Use env. to get the required type.
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template