//检查浏览器种类及其版本号 function checkBrowserVersion(){ var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox/([d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome/([d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version/([d.]+).*safari/)) ? Sys.safari = s[1] : 0; //以下进行测试 if (Sys.ie) return {"browser":"IE","version":Sys.ie}; if (Sys.firefox) return {"browser":"Firefox","version":Sys.firefox}; if (Sys.chrome) return {"browser":"Chrome","version":Sys.chrome}; if (Sys.opera) return {"browser":"Opera","version":Sys.opera}; if (Sys.safari) return {"browser":"Safari","version":Sys.safari}; } checkBrowserVersion(); /* {browser: "Chrome", version: "61.0.3163.100"} */
引用文献:
JS 获得浏览器类型和版本:https://segmentfault.com/a/1190000007640795