Determine whether it’s Android or ios

Method 1.

let u = navigator.userAgent let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 let isiOS = !! u.match(/\(i[^;] +; ( U;) ? CPU.+Mac OS X/)Copy the code

Method 2.

let isAndroid = navigator.userAgent.match(/android/gi) let isIPhone = navigator.userAgent.match(/iphone/gi) let isIpad =  navigator.userAgent.match(/ipad/gi)Copy the code

Determine whether it is wechat

let isWx = navigator.userAgent.toLocaleLowerCase().indexOf('micromessenger') > - 1
Copy the code

Check whether it is mobile terminal or PC terminal

let isIOS = navigator.userAgent.match(/iPhone|iPad|iPod/gi)
let isMobile = isIOS || navigator.userAgent.match(/Android|BlackBerry|Opera Mini|IEMobile/gi)
if(isMobile) {// mobileelse{// PC}Copy the code

Fall in love with a sentence

All progress comes from the challenge of disbelief.