判断是电脑还是手机访问

<script type="text/javascript"> 
 var userAgentInfo = navigator.userAgent;
   var Agents = ["Android", "iPhone",
      "SymbianOS", "Windows Phone",
      "iPad", "iPod"];
   var flag = true;
   for (var v = 0; v < Agents.length; v++) {
      if (userAgentInfo.indexOf(Agents[v]) > 0) {
         flag = false;
         break;
      }
   }

script> 
<script>  
    //判断访问设备,方便后面针对不同设备调用代码  
    var dev = "";  
    if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {  
        //设备为移动端  
        dev = "mobile";  
    }  
    else {  
        //设备为pc  
        dev = "pc";  
    }  
    console.log("当前使用设备为:" + dev);  
script>  

你可能感兴趣的:(JavaScript)