1. 程式人生 > >js獲取瀏覽器版本信息

js獲取瀏覽器版本信息

引入 num gen style chrom firefox html bstr pan

//獲取當前瀏覽器類型和版本號
"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 即可

js獲取瀏覽器版本信息