1.只判断类型:
if (!!window.ActiveXObject || "ActiveXObject" in window) { console.info("ie"); }else{ if(navigator.userAgent.indexOf("Chrome")!=-1||navigator.userAgent.indexOf("Safari")!=-1) { console.info("webkit"); }else if(navigator.userAgent.indexOf("Firefox")!=-1){ console.info("Firefox") } // else ... }
2.判断 类型 + 版本
window.GLOBAL = { //浏览器版本信息 BROWSER : (function() { var u = window.navigator.userAgent.toLocaleLowerCase(), msie = /(msie) ([\d.]+)/, chrome = /(chrome)\/([\d.]+)/, firefox = /(firefox)\/([\d.]+)/, safari = /(safari)\/([\d.]+)/, opera = /(opera)\/([\d.]+)/, ie11 = /(trident)\/([\d.]+)/, b = u.match(msie)||u.match(chrome)||u.match(firefox)||u.match(safari)||u.match(opera)||u.match(ie11); return {NAME: b[1], VERSION: parseInt(b[2])}; })() }
3.JS获取浏览器信息
浏览器代码名称:navigator.appCodeName
浏览器名称:navigator.appName
浏览器版本号:navigator.appVersion
对Java的支持:navigator.javaEnabled()
MIME类型(数组):navigator.mimeTypes
系统平台:navigator.platform
插件(数组):navigator.plugins
用户代理:navigator.userAgent