y-shmily

vue判断客户端类型是手机还是电脑

<script type="text/javascript">
    function browserRedirect() {
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = 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) == "ucweb";
        var bIsAndroid = sUserAgent.match(/android/i) == "android";
        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
        } else {
            const mUrl = location.origin + location.pathname.replace(/m/, "p") + location.search;
            console.log(mUrl);
            location.href = mUrl;
        }
    }
    browserRedirect();
</script>

转载至网络,如有侵权,联系作者。

分类:

技术点:

相关文章:

  • 2021-12-22
  • 2021-12-12
  • 2021-09-06
  • 2021-09-27
  • 2021-12-22
  • 2021-12-18
  • 2021-10-19
  • 2021-12-10
猜你喜欢
  • 2021-09-06
  • 2021-10-19
  • 2021-11-26
  • 2021-10-05
  • 2021-09-29
  • 2021-12-08
  • 2021-12-22
相关资源
相似解决方案