判断设备是PC端,还是移动端
1 //判断设备 alert 20160512 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); 17 18 if(mobileType.pc == false){ 19 return; 20 }
时间: 2024-10-12 13:02:19