js实现IE访问网站推荐使用其它浏览器

103 阅读1分钟

微软给出了 IE 11 桌面应用程序的「退役」时间表:2021 年 8 月 17 日,Microsoft 365 等 app 将停止支持 IE 11;2022 年 6 月 15 日,停止支持 IE11 桌面应用程序。

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    body {
      padding: 10px;
    }
    .div1,
    .div2,
    .div3,
    .div4,
    .div5 {
      width: 30px;
      height: 30px;
      border: 1px solid black;
      border-radius: 50%;
      float: left;
      margin-right: 5px;
    }
    .div1,
    .div3,
    .div4 {
      background: linear-gradient(to top, yellow, pink, rgb(63, 44, 46));
    }
    .div6 {
      width: 15px;
      height: 15px;
      /* border: 1px solid black; */
      border-radius: 15px 0 0 0;
      background-color: rgb(243, 196, 255);
    }
    .div2,
    .div3,
    .div4,
    .div5 {
      background-color: none;
    }
  </style>
</head>
<body>
  <div class="div1"></div>

  <div class="div3"></div>
  <div class="div4"></div>
  <div class="div2">
    <div class="div6"></div>
  </div>
  <div class="div5"></div>
</body>
<script type="text/javascript">
  (function (window) {
    var userAgent = navigator.userAgent;
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if (isIE || isIE11) {
      var str = "你的浏览器已经和时代脱轨了 :(";
      var str2 = "推荐使用:谷歌,"
        + "火狐"
        + "等其他浏览器";
      document.writeln("<pre style='text-align:center;color:#fff;background-color:#195B40; height:100%;border:0;position:fixed;top:0;left:0;width:100%;z-index:1234'>" +
        "<h2 style='padding-top:200px;margin:0'><strong>" + str + "<br/></strong></h2><h2>" +
        str2);
      $('body').css('background', '#fff');
      document.execCommand("Stop");
    }
  })(window)
  $("#captchaimg").on("click", function () {
    location.reload();
  });
</script>
</html>

IE浏览器访问效果
image.png
其它浏览器访问效果
image.png