判断浏览器版本

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="%PUBLIC_URL%/hack.css" rel="stylesheet" />
</head>
<body>
    <div id="root">欢迎大家</div>
    <div id="hack" class="hack" style="display: none;">
        <div class="banner-top"></div>
        <div class="hack-content">
          <h2>
            为了您更好的使用项目运营管理系统,请使用Chrome、Safari、Firefox、IE11等现代浏览器。
          </h2>
          <p>
            如采用了IE内核的360、QQ等浏览器出现异常,请查看是否开启了低版本的兼容模式。
          </p>
        </div>
        <div class="banner-top banner-bottom"></div>
    </div>
    <script type="text/javascript">
        (function () {
          var ie = !!(window.attachEvent && !window.opera);
          var wk = /webkit/(d+)/i.test(navigator.userAgent) && RegExp.$1 < 525;
          var fn = [];
          var run = function () {
            for (var i = 0; i < fn.length; i++) fn[i]();
          };
          var d = document;
          d.ready = function (f) {
            if (!ie && !wk && d.addEventListener)
              return d.addEventListener("DOMContentLoaded", f, false);
            if (fn.push(f) > 1) return;
            if (ie)
              (function () {
                try {
                  d.documentElement.doScroll("left");
                  run();
                } catch (err) {
                  setTimeout(arguments.callee, 0);
                }
              })();
            else if (wk)
              var t = setInterval(function () {
                if (/^(loaded|complete)$/.test(d.readyState))
                  clearInterval(t), run();
              }, 0);
          };
        })();
        function IETester(userAgent) {
          var UA = userAgent || navigator.userAgent;
          if (/msie/i.test(UA)) {
            return UA.match(/msie (d+.d+)/i)[1];
          } else if (~UA.toLowerCase().indexOf("trident") && ~UA.indexOf("rv")) {
            return UA.match(/rv:(d+.d+)/)[1];
          }
          return false;
        }
        function reactError() {
          setTimeout(function () {
            var app = document.getElementById("root");
            if (app.children && app.children.length === 0) {
              document.getElementById("react-error").style.display = "block";
            }
          }, 60000);
        }
        function reload() {
          window.location.replace(window.location.origin);
        }
        window.IEVERSION = parseInt(IETester());
        document.ready(function () {
          if (parseInt(IETester()) <= 10) {
            document.getElementById("root").style.display = "none";
            document.getElementById("hack").style.display = "block";
          } else {
            reactError();
          }
        });
      </script>
</body>
</html>
原文地址:https://www.cnblogs.com/MDGE/p/13570857.html