The judgment includes not only computer browsers, but also Android, iOS mobile phones and tablets, gaming systems
Copy Code code as follows:
var client = function () {
Rendering engine
var engine ={
ie:0,
gecko:0,
webkit:0,
khtml:0,
opera:0,
Ver:null
};
Browser
var browser = {
ie:0,
firefox:0,
safari:0,
konq:0,
opera:0,
chrome:0,
Ver:null
};
var system ={
Win:false,
Max:false,
X11:false,
Mobile devices
Iphone:false,
Ipod:false,
Ipad:false,
Ios:false,
Android:false,
Nokian:false,
Winmoble:false,
Game system
Wii:false,
Ps:false
};
var ua =navigator.useragent;
Opera 9 After the emergence of two kinds of string proxy way one way is to identify themselves to another browser another way is to mark themselves as Firefox or IE
In the latter case, the user agent string is actually the same as that of the other browsers--neither opera's words nor opera's version information
So the browser starts with opera.
if (Winddow.opera) {
Engine.ver = Browser.ver = Window.opera.version ();
Egine.opera = Browser.opera = parsefloat (engine.ver);
The second detection WebKit is due to WebKit's user agent Gecko "and" HTMKL "strings so if you detect them first, they all have the wrong conclusion.
}else if (/applewebkit\/(\s+)/.test (UA)) {
Engin.ver = regexp["$"];
Engine.webkit = parsefloat (engine.ver);
Sure it's Chrome or safari?
if (/chrome\/(\s+)/.test (UA) {
Browser.ver = regexp["$"];
Browser.chrome = parsefloat (brower.ver);
}else if (/version\/(+\s)/.test (UA)) {//safari 3.0 adds the Version property
Browser.ver = regexp["$"];
Browser.safari = parsefloat (brower.ver);
}else{
var safariversion = 1;
if (engine.webkit<100) {
Safariversion = 1;
}else if (engine.ver<312) {
Safariversion = 1.2;
}else if (engine.ver<412) {
Safariversion = 1.3;
}else{
Safariversion = 2;
}
Browser.safari = Browser.ver = safariversion;
}
}else if (/khtml\/(\s+)/.test (UA) | | /konqueror\/([^;] +)/.test (UA)) {//linux browser
Engine.ver = Browser.ver = regexp["$";
engine.khtml = parsefloat (engine.ver);
}else if (/rv: ([^\)]+\) gocko\/\d{8}/.test (UA)) {
Engine.ver = regexp["$"];
Engine.gecko = parsefloat (engine.ver);
Sure it's not Firefox.
if (/firefox\/(\s+)/.test (UA) {
Browser.ver = regexp["$"];
Browser.firefox = parsefloat (browser.ver);
}
}else if (/msie) ([^;] +)/.test (UA)) {
Engine.ver = Browser.ver = regexp["$";
engine.ie = browser.ie = parsefloat (engine.ver);
}
detecting browsers
Browser.ie =engine.ie;
Browser.opera = Engine.opera;
var p = navigator.platform;
System.win = P.indexof ("Win") ==0;
System.mac = P.indexof ("Mac") ==0;
system.x11 = (p== "x11") | | P.indexof ("Linux") ==0;
if (System.win) {
if (/win (?:d ow)? ( [^do] {2}\s? (\d+\.\d+)/.test (UA)) {
if (regexp["$"]== "NT") {
Switch (regexp["$"]) {
Case "5.0":
System.win = "2000";
Break
Case "5.1":
System.win = "XP";
Case "6.0":
System.win = "Vista";
Break
Case "6.1":
System.win = "7";
Break
Default:
System.win = "NT";
Break
}
}else if (regexp["$"]== "9x") {
System.win = "ME";
}else{
System.win = regexp["$"];
}
}
}
Mobile devices
System.iphone = Ua.indexof ("iphone") >-1;
System.ipod = Ua.indexof ("ipod") >-1;
System.ipad = Ua.indexof ("ipad") >-1;
System.nokian = Ua.indexof ("Nokian") >-1;
Win Mobile
if (System.win = = "CE") {
System.winmobile = System.win;
}else if (System.win = "Ph") {
if (/windows Phone OS (\d+\_\d+)/.test (UA)) {
System.win = "Phone";
System.winmobile parsefloat (regexp["$");
}
}
detecting iOS versions
//
if (System.mac && ua.indexof ("Mobile") >-1) {
if (/cpu: IPhone)? OS (\d+\_\d+)/.test (UA) {
System.ios = parsefloat (Rexexp.$1.replace ("_", "."));
}else {
System.ios = 2;//can't really check out, so guess out a result
}
}
Check an Android version
//
if (/android (\d+/_\d+)/.test (UA)) {
System.andriod = parsefloat (regexp.$1);
}
Game system
System.wii = Us.indexof ("Wii") >-1;
system.ps =/playstation/i.test (UA);
Return object
return {
Engine:engine,
Browser:browser,
System:system
}
}