JS代码识别扫码设备

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>扫码下载</title>
</head>
<body>
 
  <script>
 

    goDownload();
 
    // 去下载
    function goDownload()
    {
      var u = navigator.userAgent, app = navigator.appVersion;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
      var isIOS = !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/);
      
      // 是安卓浏览器
      if (isAndroid)
      {
        window.location.href = 'http://www.baidu.com';
      }
      
      // 是iOS浏览器
      if (isIOS)
      {
        window.location.href = 'https://www.baidu.com';
      }
 
      // 是微信内部webView
      if (is_weixn())
      {
         alert("请点击右上角按钮,点击使用浏览器打开.");
      }
 
    }
 
    // 是微信浏览器
    function is_weixn()
    {
      var ua = navigator.userAgent.toLowerCase();
      if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
      } else {
        return false;
      }
    }
 
 
    function IsPC() {
      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;
        }
      }
      return flag;
    }
 
  </script>
</body>
</html>

原文地址:https://www.cnblogs.com/xuandi/p/8806449.html