Skip to content

Instantly share code, notes, and snippets.

@earlonrails
earlonrails / getBrowser.js
Last active December 15, 2015 13:19
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!
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];
}