zoukankan      html  css  js  c++  java
  • js判断当前浏览器是pc端还是移动端

    根据用户的访问设备的不同来显示不同的页面样式,主要是判断移动设备还是电脑浏览器访问的。

    下面给出js判断处理代码,以作参考。

     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             } else {
    16                 document.writeln("pc");
    17             }
    18         }
    19 
    20         browserRedirect();
    21     </script>
  • 相关阅读:
    asy for
    asy html !
    lib
    git clone 指定 version tag
    git tag
    git clone <url>--depth 、 git clone <url> --recursive
    xelatex CLI
    rsync
    curl options
    [转自]C语言offset_of宏和container_of宏
  • 原文地址:https://www.cnblogs.com/litter/p/6953168.html
Copyright © 2011-2022 走看看