根据不同设备跳转到不同的网站(pc端网站和移动端网站)

created() {
    var url = window.location.pathname;
    var pcurl = "http://www.xxx.com" + url;
    if (
      /AppleWebKit.*Mobile/i.test(navigator.userAgent) == false ||
      /MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(
        navigator.userAgent
      ) == false
    ) {
      if (window.location.href.indexOf("?mobile") < 0) {
        try {
          if (
            /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ==
            false
          ) {
            //跳转操作
            }
          } else {
          }
        } catch (e) {}
      }
    }
  },

上面是移动端,下面是pc端代码:

//根据不同设备跳转到不同网站
if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
    if (window.location.href.indexOf("?mobile") < 0) {
        try {
            if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
               跳转操作
            } else {
            }
        } catch (e) { }
    }
} else {
    console.log("mobile");
}

 

你可能感兴趣的:(根据不同设备跳转到不同的网站(pc端网站和移动端网站))