js 设备检测(判断是移动端还是PC端)

来源:互联网 发布:如何联系淘宝客服 编辑:程序博客网 时间:2024/06/09 17:18

设备检测:移动端返回true,pc端返回false
[javascript] view plain copy
  1. <script>  
  2.             //设备检测  
  3.             function detectmob() {  
  4.                 if( navigator.userAgent.match(/Android/i)  
  5.                 || navigator.userAgent.match(/webOS/i)  
  6.                 || navigator.userAgent.match(/iPhone/i)  
  7.                 || navigator.userAgent.match(/iPad/i)  
  8.                 || navigator.userAgent.match(/iPod/i)  
  9.                 || navigator.userAgent.match(/BlackBerry/i)  
  10.                 || navigator.userAgent.match(/Windows Phone/i)  
  11.                 ){  
  12.                     return true;  
  13.                 }  
  14.                 else {  
  15.                     return false;  
  16.                 }  
  17.             }  
  18.             alert(detectmob());  
  19.         </script>  

原创粉丝点击