Vue项目在ie浏览器中显示白屏优化提示

在工作中用到Vue开发项目,用户在IE浏览器打开页面,结果显示空白屏。作为开发者当然知道是浏览器版本过低导致语法不支持,但是用户不知情的情况下显示空白屏就很不友好。这时候有必要在页面上做点提示语告诉用户切换浏览器,下面是页面效果:

代码实现:

 

关键代码:

<script type="text/javascript">

      (function(window) {

          var theUA = window.navigator.userAgent.toLowerCase();

          if ((theUA.match(/msie\s\d+/) && theUA.match(/msie\s\d+/)[0]) || (theUA.match(/trident\s?\d+/) && theUA.match(/trident\s?\d+/)[0])) {

              var ieVersion = theUA.match(/msie\s\d+/)[0].match(/\d+/)[0] || theUA.match(/trident\s?\d+/)[0];

              if (ieVersion < 11) {

                  var str = "你的浏览器版本太低了,已经和时代脱轨了!";

                  var str2 = "推荐使用:谷歌(Chrome)浏览器";

                  document.writeln("<pre style='text-align:center;color:#fff;background-color:#0cc; 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);

                  document.execCommand("Stop"); 

              };

          }

      })(window);

    </script>

 

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-12 19:26:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-12 19:26:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-12 19:26:01       87 阅读
  4. Python语言-面向对象

    2024-01-12 19:26:01       96 阅读

热门阅读

  1. 五个大幅提升开发效率的VS Code技巧

    2024-01-12 19:26:01       51 阅读
  2. C语言——字符串常量初始化

    2024-01-12 19:26:01       54 阅读
  3. Redis的过期策略

    2024-01-12 19:26:01       54 阅读
  4. 【PostgreSQL】表管理-分区表

    2024-01-12 19:26:01       43 阅读
  5. QT 设置鼠标样式

    2024-01-12 19:26:01       52 阅读
  6. 【mysql】Mac安装mysql

    2024-01-12 19:26:01       55 阅读
  7. uniapp生命周期

    2024-01-12 19:26:01       53 阅读
  8. TDengine 签约积成电子

    2024-01-12 19:26:01       57 阅读