js判断设备(转)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>js判断设备类型是移动设备还是PC设备</title>
  <script type="text/javascript">
    // borwserRedirect
    (function browserRedirect(){
      var sUserAgent = navigator.userAgent.toLowerCase();
      var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
      var bIsIphone = sUserAgent.match(/iphone os/i) == 'iphone os';
      var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
      var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
      var bIsUc = sUserAgent.match(/ucweb/i) == 'web';
      var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
      var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';

      if(bIsIpad || bIsIphone || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM){
        window.location.href = 'http://www.163.com/';
      }else{
        window.location.href = 'http://www.baidu.com/';
      }
    })();
  </script>
</head>
<body>
  <h1>pc浏览</h1>
</body>
</html>
原文地址:https://www.cnblogs.com/limit1/p/4688288.html