Skip to content

Instantly share code, notes, and snippets.

@bronzehedwick
Last active September 19, 2016 19:38
Show Gist options
  • Save bronzehedwick/e324e583f14df4b65fba to your computer and use it in GitHub Desktop.
Save bronzehedwick/e324e583f14df4b65fba to your computer and use it in GitHub Desktop.
Dumb browser detection...
/**
* Determines (poorly) the current browser.
* @returns {string} the current browser or 'unknown'.
*/
function getBrowser() {
var ua = navigator.userAgent;
var browsers = [
'Vivaldi',
'OPR', // Opera
'Firefox',
'Chrome',
'Safari'
];
for ( let i = 0, length = browsers.length; i < length; i++ ) {
if ( ua.includes( browsers[i] ) ) {
return browsers[i];
}
}
return 'unknown';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment