码迷,mamicode.com
首页 > 移动开发 > 详细

js判断游览器是移动端还是PC端

时间:2015-12-31 17:28:26      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

 

js判断网页游览器是移动端还是PC端

 

技术分享
 1    <script type="text/javascript">
 2         function browserRedirect() {
 3             var sUserAgent = navigator.userAgent.toLowerCase();
 4             var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
 5             var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
 6             var bIsMidp = sUserAgent.match(/midp/i) == "midp";
 7             var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
 8             var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
 9             var bIsAndroid = sUserAgent.match(/android/i) == "android";
10             var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
11             var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
12             //document.writeln("您的浏览设备为:");
13             if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
14                 // document.writeln("phone");
15                 alert("您的浏览设备为:移动端");
16             } else {
17                 alert("您的浏览设备为:pc");
18                // document.writeln("pc");
19             }
20         }
21 
22         browserRedirect();
23     </script>
View Code

 

js判断游览器是移动端还是PC端

标签:

原文地址:http://www.cnblogs.com/itslives-com/p/browserRedirect.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!