JS获取安卓和IOS版本

754 阅读1分钟
获取userAgent
const ua = navigator.userAgent.toLowerCase();
判断是否安卓
const isAndroid = () => {
  return ua.indexOf('android') > -1 || ua.indexOf('adr') > -1
}
判断安卓版本号
const getAndroidVer = () => {
  return ua.match(/android (.*?);/)
}
判断是否IOS
const isIos = () => {
  return !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i)
}
判断IOS版本号
const getIosVer = () => {
  return ua.match(/cpu iphone os (.*?) like mac os/)
}