判断ios/android设备;判断页面是否在微信中打开

简单版,vue判断是否在微信中:

      // 微信打开
         methods:{
               weChatOpen() {
                    return navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1;
               },
         }
         
         var _self = this;
         if (_self.weChatOpen()){
         //在微信中
         }

简单版,vue判断是否是ios设备:

      methods:{
	        isIosApp() {
	            return /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
	        },
      }
      
         var _self = this;
       if (_self.isIosApp()){
         //在ios中
         }

判断ios/android设备:

 var uInIOS = navigator.userAgent;
<!-- android终端-->
 var isAndroid = uInIOS.indexOf('Android') > -1 || uInIOS.indexOf('Adr') > -1; 
 <!--  in android且安卓版本大于8.6-->
  if (isAndroid && /\/([0-9\.]{1,})\//.exec(uaInApp)[1] >= "8.6") {}
 <!-- in ios且ios版本大于8.4  -->
 if (!isAndroid && /\/([0-9\.]{1,})\//.exec(uaInApp)[1] >= "8.4") {}

判断页面是否在微信中打开:

    var ua = window.navigator.userAgent.toLowerCase();
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
      <!--在微信中打开-->
    }

判断页面是否在某软件中打开:

    var uaInApp = navigator.userAgent.toLowerCase();
     <!--判断页面在听力软件内打开,此app的uaInApp中带有eusoft_ting字段  -->
     if (uaInApp.indexOf('eusoft_ting') > -1) {}

猜你喜欢

转载自blog.csdn.net/wcy7916/article/details/85765627
今日推荐