javascript 浏览器检测 -- 涵盖主流浏览器
/** * @author wsf * 检测浏览器版本 */ var browser = { "explorer": { "ie": /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+\)$/, "firefox": /firefox\/([\d.]+)/, "chrome": /chrome\/([\d.]+)/, "opera": /opera.([\d.]+)/, "safari": /version\/([\d.]+).*safari/, "se" : /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+; 360se\)$/,//360浏览器 "sougou" : /msie ([\d.]+).*\.net clr (\d\.){1,2}\d+; .*metasr.*\d\)$/,//搜狗浏览器 "maxthon" : /maxthon\/([\d.]+)///遨游浏览器webkit } }; /** * 判断浏览器代码 */ var userAgent = navigator.userAgent.toLowerCase(); var expName = null; (expName = userAgent.match(browser.explorer.ie)) ? browser.ie = expName[1] : (expName = userAgent.match(browser.explorer.firefox)) ? browser.firefox = expName[1] : (expName = userAgent.match(browser.explorer.chrome)) ? browser.chrome = expName[1] : (expName = userAgent.match(browser.explorer.opera)) ? browser.opera = expName[1] : (expName = userAgent.match(browser.explorer.safari)) ? browser.safari = expName[1] : (expName = userAgent.match(browser.explorer.se)) ? browser.se = expName[1] : (expName = userAgent.match(browser.explorer.sougou)) ? browser.sougou = expName[1] : (expName = userAgent.match(browser.explorer.maxthon)) ? browser.maxthon = expName[1] : false; ***************************调用******************** if(browser.ie === 6){ //ie6 }else if (browser.ie === 7){ //ie7 }else if(browser.ie === 8){ ///ie8 }else if(browser.ie === 9){ //ie9 }等
相关推荐
SafariSheree 2018-02-06
80437916 2020-04-11
WinerChopin 2020-03-03
程序员俱乐部 2020-02-21
cfang00 2013-05-15
流年浅滩 2015-06-14
MaureenChen 2014-05-28
囧芝麻 2019-12-28
jjddrushi 2019-12-27
Safari浏览器 2019-12-23
Safari浏览器 2019-12-11
letheashura 2019-12-03
宇智波鼬 2014-01-20
89357940 2014-01-14
Teresasmida 2014-01-10
Congpanpan 2013-09-04