1. jquery自带内核可通过window.navigator.userAgent 对象包含浏览器Version等相关信息;
自定义脚本如下:判断名称、版本号等相关信息
1 // browser check-----start 2 3 4 var userAgent = navigator.userAgent, // userAgent 5 rMsie = /.*(msie) ([\w.]+).*/, // ie 6 rFirefox = /.*(firefox)\/([\w.]+).*/, // firefox 7 rOpera = /(opera).+version\/([\w.]+)/, // opera 8 rChrome = /.*(chrome)\/([\w.]+).*/, // chrome 9 rSafari = /.*version\/([\w.]+).*(safari).*/;// safari 10 var jMeteor={}; 11 jMeteor.browser = {}; 12 var ua = userAgent.toLowerCase(); 13 function uaMatch(ua) { 14 var match = rMsie.exec(ua); 15 if (match != null) { 16 return { browser : match[1] || "", version : match[2] || "0" }; 17 } 18 var match = rFirefox.exec(ua); 19 if (match != null) { 20 return { browser : match[1] || "", version : match[2] || "0" }; 21 } 22 var match = rOpera.exec(ua); 23 if (match != null) { 24 return { browser : match[1] || "", version : match[2] || "0" }; 25 } 26 var match = rChrome.exec(ua); 27 if (match != null) { 28 return { browser : match[1] || "", version : match[2] || "0" }; 29 } 30 var match = rSafari.exec(ua); 31 if (match != null) { 32 return { browser : match[2] || "", version : match[1] || "0" }; 33 } 34 if (match != null) { 35 return { browser : "", version : "0" }; 36 } 37 } 38 var browserMatch = uaMatch(userAgent.toLowerCase()); 39 if (browserMatch.browser) { 40 jMeteor.browser[browserMatch.browser] = true; 41 jMeteor.browserName = browserMatch.browser; 42 jMeteor.browser.version = browserMatch.version; 43 jMeteor.browser.language = (navigator.language ? navigator.language 44 : navigator.userLanguage || ""); 45 } 46 //// browser check-----end 47 //console.log(jMeteor.browser.msie); //判断是否为ie,返回true则代表是 48 //console.log(jMeteor.browserName); //浏览器名称 49 //console.log(jMeteor.browser.version); //浏览器版本 50 //console.log(jMeteor.browser.language);//语言