码迷,mamicode.com
首页 > 其他好文 > 详细

vue项目检测IE浏览器版本,版本太低给出提示

时间:2020-08-26 18:50:56      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:osi   版本   user   navig   target   padding   极速   gen   ie11   

在index.html 文件的header标签内加入:

<script type="text/javascript">
      function IEVersion() {
        var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
        var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
        var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
        var isIE11 = userAgent.indexOf(Trident) > -1 && userAgent.indexOf("rv:11.0") > -1;
        if(isIE) {
            var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
            reIE.test(userAgent);
            var fIEVersion = parseFloat(RegExp["$1"]);
            if(fIEVersion == 7) {
                return 7;
            } else if(fIEVersion == 8) {
                return 8;
            } else if(fIEVersion == 9) {
                return 9;
            } else if(fIEVersion == 10) {
                return 10;
            } else {
                return 6;//IE版本<=7
            }   
        } else if(isEdge) {
            return edge;//edge
        } else if(isIE11) {
            return 11; //IE11  
        } else {
            return notie;//不是ie浏览器
        }
      };

      (function() {
        if (IEVersion() < 10) {
            var str = "你的浏览器版本太低了,已经和时代脱轨了 :(";
            var str2 = "推荐使用:<a href=‘https://www.baidu.com/s?ie=UTF-8&wd=%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8‘ target=‘_blank‘ style=‘color:blue;‘>谷歌</a>,"
                + "<a href=‘https://www.baidu.com/s?ie=UTF-8&wd=%E7%81%AB%E7%8B%90%E6%B5%8F%E8%A7%88%E5%99%A8‘ target=‘_blank‘ style=‘color:blue;‘>火狐</a>,"
                + "其他双核极速模式";
            document.writeln("<pre style=‘text-align:center;color:#fff;background-color:#3878ac; 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 + "</h2><h2 style=‘margin:0‘><strong>如果你使用的是双核浏览器,请切换到极速(高速)模式访问<br/></strong></h2></pre>");
            document.execCommand("Stop"); 
        };
      }());
    </script>

技术图片

 

vue项目检测IE浏览器版本,版本太低给出提示

标签:osi   版本   user   navig   target   padding   极速   gen   ie11   

原文地址:https://www.cnblogs.com/ordinary-yolanda/p/13541264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!