// 通过 userAgent 来判断浏览器是否使用了手机浏览器.

    var ua = window.navigator.userAgent,
      agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPod', 'iPad'],
      isPC = true;
    for (var i = 0, len = agents.length; i < len; i++) {
      if (ua.indexOf(agents[i]) > 0) {
        // 如果找到一个手机标识, 就设置为false并跳出循环
        isPC = false;
        break;
      }
    }
    // 判断如果不是pc端就将网页路由替换为手机端
    if (!isPC) {
      // 假设现在网址为: https://xxx.xxx.com/2020
      var href = window.location.href.replace('/2020/','/2020/m/');
      window.location.href = href;
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-11-30
  • 2022-02-03
  • 2022-12-23
相关资源
相似解决方案