Browser Detection Using Javascript.

navigator.browserDetection= (function(){
var ua= navigator.userAgent, tem,
M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
return M.join(' ');
})();

console.log(navigator.browserDetection); // outputs: `Chrome 92`

--

--

--

Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Vulnhub Grotesque: 2 Write-up

Use Openlayers Offline for survey!

Object.keys()

Scilla Smart Contracts: Building a dApp on Zilliqa Blockchain — Part 2

Future Indefinite Tense

future indefinite tense

Build Instagram login page with Next.js and TailwindCSS Part 4— Create floating label

JavaScript — 6 Collection Processing Methods

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Safaetul Ahasan

Safaetul Ahasan

Software Engineer

More from Medium

Javascript 101 — History, Javascript Console, Data Types, Variables

How To Deploy Django App To Heroku With Images

Teen Patti Game Winner Logic In Javascript — Teen Patti, Teen Patti pro, Variation (Like AK47…

CS50 — Tutorial 8 HTML, CSS, Javascript, DOM