Created
May 9, 2014 02:53
-
-
Save RobertWang/ca7a663e21356d7d9b2d to your computer and use it in GitHub Desktop.
[js]判断浏览器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sys_userAgent(){ | |
var userAgent = navigator.userAgent, | |
rMsie = /(msie\s|trident.*rv:)([\w.]+)/, | |
rFirefox = /(firefox)\/([\w.]+)/, | |
rOpera = /(opera).+version\/([\w.]+)/, | |
rChrome = /(chrome)\/([\w.]+)/, | |
rSafari = /version\/([\w.]+).*(safari)/; | |
var browser,version,ua; | |
ua = userAgent.toLowerCase(); | |
var match = rMsie.exec(ua); | |
if (match != null) { | |
return { browser : "ie", version : match[2] || "0" }; | |
} | |
if (!!window.ActiveXObject || "ActiveXObject" in window){ | |
return { browser : "ie", version : "0"}; | |
} | |
var match = rFirefox.exec(ua); | |
if (match != null) { | |
return { browser : "firefox", version : match[2] || "0" }; | |
} | |
var match = rOpera.exec(ua); | |
if (match != null) { | |
return { browser : "opera", version : match[2] || "0" }; | |
} | |
var match = rChrome.exec(ua); | |
if (match != null) { | |
return { browser : "chrome", version : match[2] || "0" }; | |
} | |
var match = rSafari.exec(ua); | |
if (match != null) { | |
return { browser : "safari", version : match[1] || "0" }; | |
} | |
if (match != null) { | |
return { browser : "", version : "0" }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment