判断当前设备是否为移动端/手机/IOS

以vue为例:

computed: {
    //判断当前设备是否是移动端
    isMobileDevice() {
      const ua = navigator.userAgent.toLowerCase();
      const t1 = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ua);
      const t2 = !ua.match("iphone") && navigator.maxTouchPoints > 1;
      return t1 || t2;
    },

    //判断当前设备是否是手机
    isMobilePhone() {
      const ua = navigator.userAgent.toLowerCase();
      const t1 = /android|webos|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua);
      return t1 ;
    },

    //判断当前设备是否是IOS
    isIOS() {
      var u = window.navigator.userAgent;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; 
      return !isAndroid;
    },
}

猜你喜欢

转载自blog.csdn.net/weixin_44594219/article/details/127211874