Last active
December 15, 2015 13:19
-
-
Save earlonrails/5266945 to your computer and use it in GitHub Desktop.
Get Browser type and version, cleaned up from http://stackoverflow.com/a/5918791/1354978. Now also checks if it is a mobile device. Now works with IE11!
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
var getBrowser = function(){ | |
var navigatorObj = navigator.appName, | |
userAgentObj = navigator.userAgent, | |
matchVersion; | |
var match = userAgentObj.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i); | |
if( match && (matchVersion = userAgentObj.match(/version\/([\.\d]+)/i)) !== null) match[2] = matchVersion[1]; | |
//mobile | |
if (navigator.userAgent.match(/iPhone|Android|webOS|iPad/i)) { | |
return match ? [match[1], match[2], mobile] : [navigatorObj, navigator.appVersion, mobile]; | |
} | |
// web browser | |
return match ? [match[1], match[2]] : [navigatorObj, navigator.appVersion, '-?']; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment