?????????? var userAgent???? =??? navigator.userAgent, // userAgent?
??? ??? ???????? rMsie ? ? ? ? ? ? =??? /.*(msie) ([\w.]+).*/, // ie?
??? ??? ???????? rFirefox????????? =?? /.*(firefox)\/([\w.]+).*/, // firefox?
??? ??? ???????? rOpera?????????? =?? /(opera).+version\/([\w.]+)/, // opera?
??? ??? ???????? rChrome???????? =? /.*(chrome)\/([\w.]+).*/, // chrome?
??? ??? ???????? rSafari??????????? =? /.*version\/([\w.]+).*(safari).*/;// safari?
??? ???
??? ??? ???
??? ??? ??? var ua = userAgent.toLowerCase();?
??? ??? ??? function uaMatch(ua) {?
??? ??? ??? ??? var match = rMsie.exec(ua);?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : match[1] || "", version : match[2] || "0" };?
??? ??? ??? ??? }?
??? ??? ??? ??? var match = rFirefox.exec(ua);?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : match[1] || "", version : match[2] || "0" };?
??? ??? ??? ??? }?
??? ??? ??? ??? var match = rOpera.exec(ua);?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : match[1] || "", version : match[2] || "0" };?
??? ??? ??? ??? }?
??? ??? ??? ??? var match = rChrome.exec(ua);?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : match[1] || "", version : match[2] || "0" };?
??? ??? ??? ??? }?
??? ??? ??? ??? var match = rSafari.exec(ua);?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : match[2] || "", version : match[1] || "0" };?
??? ??? ??? ??? }?
??? ??? ??? ??? if (match != null) {?
??? ??? ??? ??? ??? return { browser : "", version : "0" };?
??? ??? ??? ??? }?
??? ??? ??? }?
??? ??? ??? var browserMatch = uaMatch(userAgent.toLowerCase());?
??? ??? ???
??????????? alert(browserMatch.browser+'=='+browserMatch.version);
详细解决方案
js 判断浏览器部类
热度:117 发布时间:2012-10-06 17:34:01.0
相关解决方案