function getBrowser() {
const userAgent = navigator.userAgent;
const vendor = navigator.vendor || '';
console.log('userAgent', userAgent);
console.log('vendor', vendor);
if (/OPR\//.test(userAgent) || vendor.includes('Opera')) {
return 'Opera';
} else if (/Edg\//.test(userAgent)) {
return 'Microsoft Edge';
} else if (/Chrome/.test(userAgent) && vendor.includes('Google')) {
return 'Google Chrome';
} else if (/Safari/.test(userAgent) && vendor.includes('Apple')) {
return 'Safari';
} else if (/Firefox/.test(userAgent)) {
return 'Mozilla Firefox';
} else if (/MSIE|Trident/.test(userAgent)) {
return 'Internet Explorer';
} else {
return 'Unknown Browser';
}
}
console.log('You are using: ' + getBrowser());
Xem thêm: