This article mainly introduces the js browser version, core, and mobile terminal examples. If you need them, you can refer to the browser version, core, system, and mobile terminal check.
The Code is as follows:
/**
* Check browser version
* @ Authors K
* @ Date 2014-04-11 14:48:39
* @ Version 1
*/
/**
* Detect browser info with navigator userAgent
* @ Return object browser info
*/
Var browser = (function (){
Var userAgent = navigator. userAgent,
Ua = userAgent. toLowerCase (),
BrowserList = {
Msie :/(? : Msie \ s | trident. * rv :) ([\ w.] +)/I,
Firefox:/Firefox \/([\ w.] +)/I,
Chrome:/Chrome \/([\ w.] +)/I,
Safari:/version \/([\ w.] +). * Safari/I,
Opera :/(? : OPR \/| Opera. + version \/) ([\ w.] +)/I
},
Kernels = {
MSIE:/(compatible; \ smsie \ s | Trident \/) [\ w.] +/I,
Camino:/Camino/I,
KHTML:/KHTML/I,
Presto:/Presto \/[\ w.] +/I,
Gecko:/Gecko \/[\ w.] +/I,
WebKit:/AppleWebKit \/[\ w.] +/I
},
Browser = {
Kernel: 'unknow ',
Version: 'unknow'
}
// Check the browser
For (var I in browserList ){
Var matchs = ua. match (browserList [I]);
Browser [I] = matchs? True: false;
If (matchs ){
Browser. version = matchs [1];
}
}
// Detection engine
For (var I in kernels ){
Var matchs = ua. match (kernels [I]);
If (matchs ){
Browser. kernel = matchs [0];
}
}
// System
Var OS = ua. match (/(Windows \ sNT \ s | Mac \ sOS \ sX \ s | Android \ s | ipad. * \ sos \ s | iphone \ sos \ s) ([\ d. _-] +)/I );
Browser. OS = OS! = Null? OS [0]: false;
// Whether it is mobile
Browser. mobile = ua. match (/Mobile/I )! = Null? True: false;
Return browser;
}());