判断设备是PC端,还是移动端
2 var ua = navigator.userAgent.toLocaleLowerCase(); 3 var pf = navigator.platform.toLocaleLowerCase(); 4 var isAndroid = (/android/i).test(ua)||((/iPhone|iPod|iPad/i).test(ua) && (/linux/i).test(pf)) 5 || (/ucweb.*linux/i.test(ua)); 6 var isIOS =(/iPhone|iPod|iPad/i).test(ua) && !isAndroid; 7 var isWinPhone = (/Windows Phone|ZuneWP7/i).test(ua); 8 9 var mobileType = { 10 pc:!isAndroid && !isIOS && !isWinPhone, 11 ios:isIOS, 12 android:isAndroid, 13 winPhone:isWinPhone 14 }; 15 16 console.log(mobileType.pc);