判断设备浏览器


  1. // Nodejs版本  

  2. var ua = request.headers['user-agent'],  

  3.     $ = {};  

  4.   

  5. if (/mobile/i.test(ua))  

  6.     $.Mobile = true;  

  7.   

  8. if (/like Mac OS X/.test(ua)) {  

  9.     $.iOS = /CPU( iPhone)? OS ([0-9\._]+) like Mac OS X/.exec(ua)[2].replace(/_/g, '.');  

  10.     $.iPhone = /iPhone/.test(ua);  

  11.     $.iPad = /iPad/.test(ua);  

  12. }  

  13.   

  14. if (/Android/.test(ua))  

  15.     $.Android = /Android ([0-9\.]+)[\);]/.exec(ua)[1];  

  16.   

  17. if (/webOS\//.test(ua))  

  18.     $.webOS = /webOS\/([0-9\.]+)[\);]/.exec(ua)[1];  

  19.   

  20. if (/(Intel|PPC) Mac OS X/.test(ua))  

  21.     $.Mac = /(Intel|PPC) Mac OS X ?([0-9\._]*)[\)\;]/.exec(ua)[2].replace(/_/g, '.') || true;  

  22.   

  23. if (/Windows NT/.test(ua))  

  24.     $.Windows = /Windows NT ([0-9\._]+)[\);]/.exec(ua)[1];  

  1. // js版  

  2. var isMobile = {  

  3.     Android: function() {  

  4.         return /Android/i.test(navigator.userAgent);  

  5.     },  

  6.     BlackBerry: function() {  

  7.         return /BlackBerry/i.test(navigator.userAgent);  

  8.     },  

  9.     iOS: function() {  

  10.         return /iPhone|iPad|iPod/i.test(navigator.userAgent);  

  11.     },  

  12.     Windows: function() {  

  13.         return /IEMobile/i.test(navigator.userAgent);  

  14.     },  

  15.     any: function() {  

  16.         return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());  

  17.     }  

  18. };  

  19. module.exports = {  

  20.     Android: function(ua) {  

  21.         return /Android/i.test(ua);  

  22.     },  

  23.     BlackBerry: function(ua) {  

  24.         return /BlackBerry/i.test(ua);  

  25.     },  

  26.     iOS: function(ua) {  

  27.         return /iPhone|iPad|iPod/i.test(ua);  

  28.     },  

  29.     Windows: function(ua) {

  30.         return /IEMobile/i.test(ua);  

  31.     },  

  32.     isMobile: function(ua) {  

  33.         return /Mobile/i.test(ua);  

  34.     },

  35.     isXianLiao:function(ua){

  36.         return /XLMessenger/i.test(ua);

  37.     },

  38.     isWeChat:function(ua){

  39.         return /MicroMessenger/i.test(ua);

  40.     }

  41.   }; 


注:本文转载自qiaolevip,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除。

评论0



    0.299243s