web开发中不同设备浏览器的区分

通常区分不同设备浏览器是用JavaScript中的navigator.userAgent.toLowerCase()方式获取浏览器的userAgent信息

1 //使用javascript判断是否是iPhone,Android或者ipad的浏览器
2 if ((navigator.userAgent.match(/iPhone/i))
3  || (navigator.userAgent.match(/Android/i))
4  || (navigator.userAgent.match(/Windows Phone/i))
5  || (navigator.userAgent.match(/MQQBrowser/i))
6  || (navigator.userAgent.match(/iPod/i))
7  || (navigator.userAgent.match(/iPad/i))) {
8   //进行相应的需要的操作
9 }
 1 //判断是否用微信打开
 2 
 3 function is_weixn() {
 4   var ua = navigator.userAgent.toLowerCase();
 5   if (ua.match(/MicroMessenger/i) == "micromessenger") {
 6      window.location = "tips1.html";
 7   } else { //非微信中打开
 8     window.location = "tips2.html";
 9   }
10 }
原文地址:https://www.cnblogs.com/Steven-shi/p/5129811.html