js判断是微信,IOS或Android

小知识 08-19 14:12

js判断是否微信客户端

//如果返回true 则说明是微信客户端
function isWeixin() {
  var ua = window.navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == 'micromessenger') {
    return true;
  }else{
    return false;
  }
}

js判断是否为IOS设备

function IsAppleStore() {
 var u = navigator.userAgent;
 app = navigator.appVersion;
 var ios = !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/);
 var iPad = u.indexOf('iPad') > -1;
 var iPhone = u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1;
 if (ios || iPad || iPhone) {
  return true;
 }
 else {
  return false;
 }
}

js判断是否为Android设备

function IsAndroidList() {
 var u = navigator.userAgent;
 if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {
  return true
 } else {
  return false
 }
}