低版本浏览器(chrome小于40 firefox小于50 ie小于9)会提示升级信息

window.onload=function(){

  var browserInfo1 = function (userAgent) {
      var u = userAgent || navigator.userAgent;
      var self = this;
      var match = {
          //内核
          'Trident': u.indexOf('Trident') > 0 || u.indexOf('NET CLR') > 0,
          'Presto': u.indexOf('Presto') > 0,
          'WebKit': u.indexOf('AppleWebKit') > 0,
          'Gecko': u.indexOf('Gecko/') > 0,
          //浏览器
          'Safari': u.indexOf('Safari') > 0,
          'Chrome': u.indexOf('Chrome') > 0 || u.indexOf('CriOS') > 0,
          'IE': u.indexOf('MSIE') > 0 || u.indexOf('Trident') > 0,
          'Edge': u.indexOf('Edge') > 0,
          'Firefox': u.indexOf('Firefox') > 0,
          'Opera': u.indexOf('Opera') > 0 || u.indexOf('OPR') > 0,
          'Vivaldi': u.indexOf('Vivaldi') > 0,
          'UC': u.indexOf('UC') > 0 || u.indexOf(' UBrowser') > 0,
          'QQBrowser': u.indexOf('QQBrowser') > 0,
          'QQ': u.indexOf('QQ/') > 0,
          'Baidu': u.indexOf('Baidu') > 0 || u.indexOf('BIDUBrowser') > 0,
          'Maxthon': u.indexOf('Maxthon') > 0,
          'LBBROWSER': u.indexOf('LBBROWSER') > 0,
          '2345Explorer': u.indexOf('2345Explorer') > 0,
          'Sogou': u.indexOf('MetaSr') > 0 || u.indexOf('Sogou') > 0,
          'Wechat': u.indexOf('MicroMessenger') > 0,
          'Taobao': u.indexOf('AliApp(TB') > 0,
          'Alipay': u.indexOf('AliApp(AP') > 0,
          'Weibo': u.indexOf('Weibo') > 0,
          'Suning': u.indexOf('SNEBUY-APP') > 0,
          'iQiYi': u.indexOf('IqiyiApp') > 0,
          //操作系统平台
          'Windows': u.indexOf('Windows') > 0,
          'Linux': u.indexOf('Linux') > 0,
          'Mac': u.indexOf('Macintosh') > 0,
          'Android': u.indexOf('Android') > 0 || u.indexOf('Adr') > 0,
          'WP': u.indexOf('IEMobile') > 0,
          'BlackBerry': u.indexOf('BlackBerry') > 0 || u.indexOf('RIM') > 0 || u.indexOf('BB') > 0,
          'MeeGo': u.indexOf('MeeGo') > 0,
          'Symbian': u.indexOf('Symbian') > 0,
          'iOS': u.indexOf('like Mac OS X') > 0,
          //移动设备
          'Mobile': u.indexOf('Mobi') > 0 || u.indexOf('iPh') > 0 || u.indexOf('480') > 0,
          'Tablet': u.indexOf('Tablet') > 0 || u.indexOf('iPad') > 0 || u.indexOf('Nexus 7') > 0
      };
      if (match.Mobile) {
          match.Mobile = !(u.indexOf('iPad') > 0);
      }
      //基本信息
      var hash = {
          engine: ['WebKit', 'Trident', 'Gecko', 'Presto'],
          browser: ['Safari', 'Chrome', 'IE', 'Edge', 'Firefox', 'Opera', 'Vivaldi', 'UC', 'QQBrowser', 'QQ', 'Baidu', 'Maxthon', 'Sogou', 'LBBROWSER', '2345Explorer', 'Wechat', 'Taobao', 'Alipay', 'Weibo', 'Suning', 'iQiYi'],
          os: ['Windows', 'Linux', 'Mac', 'Android', 'iOS', 'WP', 'BlackBerry', 'MeeGo', 'Symbian'],
          device: ['Mobile', 'Tablet']
      };
      self.device = 'PC';
      self.language = (function () {
          var g = (navigator.browserLanguage || navigator.language);
          var arr = g.split('-');
          if (arr[1]) {
              arr[1] = arr[1].toUpperCase();
          }
          return arr.join('-');
      })();
      for (var s in hash) {
          for (var i = 0; i < hash[s].length; i++) {
              var value = hash[s][i];
              if (match[value]) {
                  self[s] = value;
              }
          }
      }
      //系统版本信息
      var osVersion = {
          'Windows': function () {
              var v = u.replace(/^.*Windows NT ([\d.]+);.*$/, '$1');
              var hash = {
                  '6.4': '10',
                  '6.3': '8.1',
                  '6.2': '8',
                  '6.1': '7',
                  '6.0': 'Vista',
                  '5.2': 'XP',
                  '5.1': 'XP',
                  '5.0': '2000'
              };
              return hash[v] || v;
          },
          'Android': function () {
              return u.replace(/^.*Android ([\d.]+);.*$/, '$1');
          },
          'iOS': function () {
              return u.replace(/^.*OS ([\d_]+) like.*$/, '$1').replace(/_/g, '.');
          },
          'Mac': function () {
              return u.replace(/^.*Mac OS X ([\d_]+).*$/, '$1').replace(/_/g, '.');
          }
      }
      self.osVersion = '';
      if (osVersion[self.os]) {
          self.osVersion = osVersion[self.os]();
      }
      //浏览器版本信息
      var version = {
          'Chrome': function () {
              return u.replace(/^.*Chrome\/([\d.]+).*$/, '$1');
          },
          'IE': function () {
              var v = u.replace(/^.*MSIE ([\d.]+).*$/, '$1');
              if (v == u) {
                  v = u.replace(/^.*rv:([\d.]+).*$/, '$1');
              }
              return v != u ? v : '';
          },
          'Edge': function () {
              return u.replace(/^.*Edge\/([\d.]+).*$/, '$1');
          },
          'Firefox': function () {
              return u.replace(/^.*Firefox\/([\d.]+).*$/, '$1');
          },
          'Safari': function () {
              return u.replace(/^.*Version\/([\d.]+).*$/, '$1');
          },
          'Opera': function () {
              return u.replace(/^.*Opera\/([\d.]+).*$/, '$1');
          },
          'Vivaldi': function () {
              return u.replace(/^.*Vivaldi\/([\d.]+).*$/, '$1');
          },
          'Maxthon': function () {
              return u.replace(/^.*Maxthon\/([\d.]+).*$/, '$1');
          },
          'QQBrowser': function () {
              return u.replace(/^.*QQBrowser\/([\d.]+).*$/, '$1');
          },
          'QQ': function () {
              return u.replace(/^.*QQ\/([\d.]+).*$/, '$1');
          },
          'Baidu': function () {
              return u.replace(/^.*BIDUBrowser[\s\/]([\d.]+).*$/, '$1');
          },
          'UC': function () {
              return u.replace(/^.*UC?Browser\/([\d.]+).*$/, '$1');
          },
          '2345Explorer': function () {
              return u.replace(/^.*2345Explorer\/([\d.]+).*$/, '$1');
          },
          'Wechat': function () {
              return u.replace(/^.*MicroMessenger\/([\d.]+).*$/, '$1');
          },
          'Taobao': function () {
              return u.replace(/^.*AliApp\(TB\/([\d.]+).*$/, '$1');
          },
          'Alipay': function () {
              return u.replace(/^.*AliApp\(AP\/([\d.]+).*$/, '$1');
          },
          'Weibo': function () {
              return u.replace(/^.*weibo__([\d.]+).*$/, '$1');
          },
          'Suning': function () {
              return u.replace(/^.*SNEBUY-APP([\d.]+).*$/, '$1');
          },
          'iQiYi': function () {
              return u.replace(/^.*IqiyiVersion\/([\d.]+).*$/, '$1');
          }
      };
      self.version = '';
      if (version[self.browser]) {
          self.version = version[self.browser]();
      }
  };
  var browserInfo = new browserInfo1();
  var uDivContent = document.createElement('div');
  var uDivWarp = document.createElement('div');
  var uDivContentHTML = '
温馨提示:

您当前的浏览器版本过低,可能存在安全风险,请升级浏览器,并设置新安装的浏览器为默认浏览器

'
uDivContent.id = 'uDivContent' uDivWarp.id = 'uDivWarp' if (browserInfo.browser === "IE" && Math.floor(Number(browserInfo.version))<8) { uDivWarp.style.position = 'absolute'; uDivWarp.style.width = '100%'; uDivWarp.style.height = '100%'; uDivWarp.style.backgroundColor = '#fff'; uDivWarp.style.opacity = '0.1'; uDivWarp.style.left = '0'; uDivWarp.style.top = '0'; uDivWarp.style.zIndex = '1000'; uDivContent.style.position = 'absolute'; uDivContent.style.width = '400px'; uDivContent.style.height = '210px'; uDivContent.style.backgroundColor = '#fff'; uDivContent.style.border = '1px solid #e0e0e0'; uDivContent.style.left = '50%'; uDivContent.style.top = '50%'; uDivContent.style.marginTop = '-100px'; uDivContent.style.marginLeft = '-200px'; uDivContent.style.zIndex = '1001'; uDivContent.innerHTML = uDivContentHTML; document.getElementsByTagName('body')[0].appendChild(uDivWarp); document.getElementsByTagName('body')[0].appendChild(uDivContent); }else if((browserInfo.browser === "Chrome" && Math.floor(Number(browserInfo.version.substring(0,2)))<40) || (browserInfo.browser === "Firefox" && Math.floor(Number(browserInfo.version))<50) || (browserInfo.browser === "IE" && Math.floor(Number(browserInfo.version)) === 8)){ uDivWarp.style.position = 'fixed'; uDivWarp.style.width = '100%'; uDivWarp.style.height = '100%'; uDivWarp.style.backgroundColor = '#fff'; uDivWarp.style.opacity = '0.1'; uDivWarp.style.left = '0'; uDivWarp.style.top = '0'; uDivWarp.style.zIndex = '1000'; uDivContent.style.position = 'fixed'; uDivContent.style.width = '400px'; uDivContent.style.height = '210px'; uDivContent.style.backgroundColor = '#fff'; uDivContent.style.border = '1px solid #e0e0e0'; uDivContent.style.left = '50%'; uDivContent.style.top = '50%'; uDivContent.style.marginTop = '-100px'; uDivContent.style.marginLeft = '-200px'; uDivContent.style.zIndex = '1001'; uDivContent.innerHTML = uDivContentHTML; document.getElementsByTagName('body')[0].appendChild(uDivWarp); document.getElementsByTagName('body')[0].appendChild(uDivContent); } document.getElementById("closeBtn").onclick = function(){ document.getElementById('uDivContent').style.display = 'none' document.getElementById('uDivWarp').style.display = 'none' } }

你可能感兴趣的:(浏览器兼容提示)