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.