Skip to content

Instantly share code, notes, and snippets.

@moiseshilario
Created October 3, 2018 20:08
Show Gist options
  • Save moiseshilario/6a382341c36770b8dcfdb5a5e5e43998 to your computer and use it in GitHub Desktop.
Save moiseshilario/6a382341c36770b8dcfdb5a5e5e43998 to your computer and use it in GitHub Desktop.
Browser Detection
function BrowserDetection() {
//Check if browser is IE
if (navigator.userAgent.search('MSIE') !== -1) {
console.log('IE');
}
//Check if browser is Chrome
else if (navigator.userAgent.search('Chrome') !== -1) {
console.log('Chrome');
}
//Check if browser is Firefox
else if (navigator.userAgent.search('Firefox') !== -1) {
console.log('Firefox');
}
//Check if browser is Safari
else if (navigator.userAgent.search('Safari') !== -1 && navigator.userAgent.search('Chrome') === -1) {
console.log('Safari');
}
//Check if browser is Opera
else if (navigator.userAgent.search('Opera') !== -1) {
console.log('Opera');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment