js判断是否是微信浏览器、是否是安卓、ios

368 阅读1分钟
     var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {//是否是微信浏览器
          if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {//是否是ios
                window.location = "https://hzapp.hezongyy.com/download"; //填写地址
            } else if (navigator.userAgent.match(/android/i)) { //是否是安卓
              this.$router.push('/tipsPage')
            }
        }else{ //其他的浏览器
            if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {//ios端
              window.location.href = "https://hzapp.hezongyy.com/download";  
            } else if (navigator.userAgent.match(/android/i)) { //安卓端
                window.open("yaoyigou://www.hezongyy.com",'_self')
                setTimeout(()=>{
                  let hidden=window.document.hidden||window.document.webkitHidden||window.document.mozHidden||window.document.msHidden
                  if(typeof(hidden) =="undefined"||hidden==false){
                    window.location.href="https://hzapp.hezongyy.com/download"
                  }
                },1500)
            }
        }