Vue判断IE浏览器版本并提示
首先接到这个任务时感觉很懵。首先让我们梦回2016。
然而公司竟然还有人用IE11以下的版本。你说神奇不神奇?
看了好几篇文章,搜了好多代码。下面进入正题:
原始代码放入public/index.html的< head>中:
<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 = "你的浏览器版本太low了,已经和时代脱轨了 :(";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:#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 + "</h2><h2 style='margin:0'><strong>如果你的使用的是双核浏览器,请切换到极速模式访问<br/></strong></h2></pre>");document.execCommand("Stop"); };}})(window);</script>
这里navigator.userAgent为获取浏览器信息,toLowerCase()把所有字符串改为小写。下面的判定条件看不懂了,而且代码不起作用,后面加入else后可以进入else。所以做了以下改动。
<script type="text/javascript">(function(window) {var theUA = window.navigator.userAgent.toLowerCase();console.log(theUA);if (// theUA.indexOf('trident') > -1 && theUA.indexOf('rv:11.0') > -1theUA.indexOf("compatible") > -1 && theUA.indexOf("msie") > -1) {var str = "你的浏览器版本不受支持,请及时更新";var str2 = "推荐使用:<a style='color:#fff;'>谷歌</a>,"+ "<a style='color:#fff;'>搜狗</a>,"+ "其他双核极速模式";document.writeln("<pre style='text-align:center;color:#fff;background-color:#1890FF; 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 + "");console.log("浏览器不合格")document.execCommand("Stop");}else{console.log("浏览器合格")}})(window);</script>
代码主要对if中的判定条件做了改动,theUA.indexOf(‘trident’) > -1 && theUA.indexOf(‘rv:11.0’) > -1, 判定为是否为IE11,
theUA.indexOf(“compatible”) > -1 && theUA.indexOf(“msie”) > -1, 判断为是否为ie11以下版本。另外可输出console.log
查看浏览器信息。
博客中还有其他完成代码,暂不涉及
Vue判断IE浏览器版本并提示相关推荐
- 判断IE浏览器版本(IE10+)
判断IE浏览器版本(IE10+) 项目不支持低版本的IE,在登录的时候通过判断浏览器版本,寄语人性化的提示,具体实现如下 可以写在在公共函数文件里,到时候直接 import { IEVersion } ...
- 判断当前浏览器版本ie浏览器跳转谷歌浏览器
判断当前浏览器版本ie浏览器跳转谷歌浏览器 在 vue 项目 index.html中 添加 function getOs() { if (navigator.userAgent.indexOf(&qu ...
- 原生js判断IE浏览器版本
// 判断IE浏览器版本function IEVersion() {var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE ...
- jquery判断ie浏览器版本
jquery判断ie浏览器版本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 < script type ...
- 手机端判断用户代理,浏览器版本,内核信息等
<script type="text/javascript">//判断访问终端var browser={versions:function(){var u = navi ...
- vue项目 因浏览器版本导致js语法错误
vue版本的项目运行时,读取地址时报 We're sorry but [项目名称] doesn't work properly without JavaScript enabled. Please e ...
- JS 判断 IE 浏览器版本
if(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVer ...
- vue判断当前浏览器为IE低版本,给出升级提示;IE11及其他浏览器正常使用
当当前浏览器为低版本浏览器,插件不支持IE低版本时候,给出友好提示. /** 新增公告按钮 */ addNotice () {// 取得浏览器的userAgent字符串var userAgent = ...
- Js判断ie浏览器版本
//判断ie11的方法function IEVersion() {var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE ...
最新文章
- 【转】[退役]纪念我的ACM——headacher@XDU
- 斗图必备!AI实战各种沙雕表情包分门别类~
- windows下安装whl文件
- wpf控件开发基础(1)
- 西游之路——python全栈——上传文件
- 使用TensorFlow的基本步骤
- git按照tag拉取代码_Git实操小课堂
- dockerfile 的使用
- monogdb操作system.*权限
- mysql存储过程返回多个值_数据库mysql存储过程之返回多个值的方法示例
- oschina mysql limit_MySQL 用 limit 为什么会影响性能?
- 解决:VScode 汉化后 、设置中文后 还显示英文的问题
- Flink学习笔记01:初探Flink - 词频统计
- 十一款游戏教你学会 CSS!
- hdu 3530 Subsequence 单调队列
- vc6.0转vc2010编程中遇到的问题
- FFmpeg源代码简单分析:avcodec_close()
- springboot12 MVC自动配置原理
- Android应用开发基础篇(13)-----GestureDetector(手势识别)
- MySQL order by、group by关键字优化