Created
July 7, 2013 22:32
-
-
Save juanbrujo/5945220 to your computer and use it in GitHub Desktop.
Gets the current browser + if it is IE, the version currentBrowser().browser to get the browsername
currentBrowser().version to get the version if it is IE
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 currentBrowser() { | |
$.returnVal = ""; | |
var browserUserAgent = navigator.userAgent; | |
if (browserUserAgent.indexOf("Firefox") > -1) { | |
$.returnVal = { browser: "Firefox" }; | |
} | |
else if (browserUserAgent.indexOf("Chrome") > -1) { | |
$.returnVal = { browser: "Chrome" }; | |
} | |
else if (browserUserAgent.indexOf("Safari") > -1) { | |
$.returnVal = { browser: "Safari" }; | |
} | |
else if (browserUserAgent.indexOf("MSIE") > -1) { | |
var splitUserAgent = browserUserAgent.split(";"); | |
for (var val in splitUserAgent) { | |
if (splitUserAgent[val].match("MSIE")) { | |
var IEVersion = parseInt(splitUserAgent[val].substr(5, splitUserAgent[val].length)); | |
} | |
} | |
$.returnVal = { browser: "IE", version: IEVersion }; | |
} | |
else if (browserUserAgent.indexOf("Opera") > -1) { | |
$.returnVal = { browser: "Opera" }; | |
} | |
else { | |
$.returnVal = | |
{ browser: "other" }; | |
} | |
return $.returnVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment