js检测浏览器类型以及版本信息

js检测浏览器类型以及版本信息

DetectBrowser () {
    
    
    const userAgent = window.navigator.userAgent
    const isChrome = userAgent.indexOf('Chrome') > -1 && userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Edge') === -1 && userAgent.indexOf('MetaSr') === -1;
    if(!isChrome){
    
    
      this.$message({
    
    
          showClose: true,
          message: '您正在使用 非Chrome 浏览器,有些功能暂不支持,可能会影响您的体验,请下载 ',
          type: 'warning',
          center:true,
          duration:0,
          offset:1,
          customClass:"prompt-tip",
          onClose:()=>{
    
    
            window.open('https://www.google.cn/chrome/')
          }
        });
      const list = userAgent.split(' ');
      list.forEach((item: any) => {
    
    
        if (item.indexOf('Chrome') !== -1){
    
    
          const chromeVersion = item.split('/')[1].split('.')[0]  
          if (Number(chromeVersion)<97){
    
    
            this.$message({
    
    
              showClose: true,
              message: '您正在使用 低版本Chrome 浏览, 有些功能暂不支持,可能会影响您的体验,请下载',
              type: 'warning',
              duration:0,
              offset:1,
              center:true,
              customClass:"prompt-tip",
              onClose:()=>{
    
    
                 window.open('https://www.google.cn/chrome/')
              }
            });
          }
          
        }
       
      })
      
    }
  }

猜你喜欢

转载自blog.csdn.net/m0_46672781/article/details/129142179