js获取浏览器版本信息

//获取当前浏览器类型和版本号
"use strict";
let agent = navigator.userAgent.toLowerCase();
let regStr_ff = /firefox\/[\d.]+/gi;
let regStr_chrome = /chrome\/[\d.]+/gi;

//IE11以下
if (agent.indexOf("msie") > 0) {
    pass;
}

//IE11版本中不包括MSIE字段
if (agent.indexOf("trident") > 0 && agent.indexOf("rv") > 0) {
    pass;
}

//firefox
if (agent.indexOf("firefox") > 0) {
    let num = agent.match(regStr_ff)[0].match(/[\d.]+/)[0].substr(0, 2);
    if (num < 58) {
       pass;
    }
}

//Chrome
if (agent.indexOf("chrome") > 0) {
    let num = agent.match(regStr_chrome)[0].match(/[\d.]+/)[0].substr(0, 2);
    if (num < 61) {
        pass;
    }
}

在HTML <head> 标签中引入js 即可

posted @ 2018-12-28 14:46  Eunuch_Li  阅读(272)  评论(0编辑  收藏  举报