判断设备是安卓,ios,微信,pc

  • 判断是安卓设备
      let _ua = navigator.userAgent;
      if(_ua.indexOf("Android") > -1 || _ua.indexOf("Linux") > -1){
       console.log("是安卓设备")
        return false;
      }
  • 判断是ios设备
let _ua = navigator.userAgent;
if(_ua.indexOf("iPhone") > -1 || _ua.indexOf("iOS") > -1){
        console.log("是ios设备")
        return true;
  }
  • 判断是不是微信
 let _ua = navigator.userAgent;
 let isWeChat=_ua.toLowerCase();
 if(isWeChat.match(/MicroMessenger/i) == "micromessenger"){
          console.log("是微信")
 }
  • 判断是不是pc
      let u = navigator.userAgent;
    if(!!u.match(/AppleWebKit.*Mobile.*/)){
        alert('手机');
    }else{
        alert('电脑');
    }

你可能感兴趣的:(判断设备是安卓,ios,微信,pc)