js判断终端是移动端还是pc端

<!doctype html>
<html>
     <meta charset="utf-8" />
     <head>
           <title>web1</title>
     </head>
     <body>
     </body>
</html>
<script type="text/javascript">
     //平台、设备和操作系统
     var system = {
           win: false,
           mac: false,
           xll: false,
           ipad: false
     };
     //检测平台
     var p = navigator.platform;
     system.win = p.indexOf("Win") == 0;
     system.mac = p.indexOf("Mac") == 0;
     system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
     system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;
     //跳转语句,如果是PC访问就自动跳转到所要访问的页面http://www.电脑.com
     if(system.win || system.mac || system.xll || system.ipad) {
           //默认访问http://www.电脑.com
           alert(11111)
     } else {
           alert(222)
     }
</script>

猜你喜欢

转载自blog.csdn.net/M_SSY/article/details/82850577
今日推荐