Don't talk much, just look at the code.
1. Differentiate Android, iphone, ipad:
var ua = navigator.useragent. toLowerCase (); if (/android|adr/gi. Test (UA)) { // android }Elseif(/\ (i[^;] +;( U;)? Cpu.+mac OS X/gi. Test (UA)) { // Apple }Elseif(/ipad/gi. Test (UA)) { //ipad }
2, differentiated equipment: Sina Weibo for the 1,QQ client is 2, less than 6.0.2 version is 3, above 6.0. The 2 version is 4, the other is 0.
varUA = Navigator.useragent.toLowerCase (); if(Ua.match (/weibo/i) = = "Weibo") {Console.Log(1);}Else if(Ua.indexof (' qq/')! =-1) {Console.Log(2);}Else if(Ua.match (/micromessenger/i) = = "Micromessenger"){ varV_weixin = ua.Split(' Micromessenger ') [1]; V_weixin= V_weixin.substring (1,6); V_weixin= V_weixin.Split(‘ ‘) [0]; if(V_weixin.Split(‘.‘). Length = = 2) {v_weixin= V_weixin + '. 0 '; } if(V_weixin < ' 6.0.2 ') {Console.Log(3);}Else{Console.Log(4); } }Else{Console.Log(0); }
3. Distinguish browsers from each other
varUa=navigator.useragent.toLowerCase (); if(/msie/i.test (UA) &&!/opera/.Test (UA)) {Alert ("IE"); return ; }Else if(/firefox/i.Test (UA)) {Alert ("Firefox"); return ; }Else if(/chrome/i.test (UA) &&/webkit/i.test (UA) &&/mozilla/i.Test (UA)) {Alert ("Chrome"); return ; }Else if(/opera/i.Test (UA)) {Alert ("Opera"); return ; }Else if(/ipad/i) {Alert ("ipad"); return ; }Else if(/webkit/i.test (UA) &&! (/chrome/i.test (UA) &&/webkit/i.test (UA) &&/mozilla/i.Test (UA))) {Alert ("Safari"); return ; }Else{alert ("Unknow"); }
Finish
JS judging various devices, various browsers