xxxxxxxxxx
navigator.userAgent.split(' ')[11].split('/')[0]
xxxxxxxxxx
//gets the type of browser
function detectBrowser() {
if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
return 'Opera';
} else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
return 'Chrome';
} else if(navigator.userAgent.indexOf("Safari") != -1) {
return 'Safari';
} else if(navigator.userAgent.indexOf("Firefox") != -1 ){
return 'Firefox';
} else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
return 'IE';//crap
} else {
return 'Unknown';
}
}
xxxxxxxxxx
// You aren't actually sure what browser they have but you have data on it. I guess
// you could return it and then find it out using 'if' and 'else if' statements
// Anyways, here you go:
// We want to alert the user about what their current browser is.
// We can use the navigator object to get the user's browser.
// Create a variable called browser and set it to the user's browser.
// Then alert the user what their browser is.
const browser = navigator.userAgent;
alert(browser);