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

Codemirror 6 Experiments

The Ultimate VSCode Setup for JS/React

Setting up CSS Modules in Typescript project

How we built better automated UI testing at Vimeo

Screenshot of a test report generated using Backbone

Getting started with React and D3 — interactive Bar Chart.

La GuezNet, les news du Web [21/06/18]

The React useState Hook

Create a Reusable OAuth React Component with Oauth.io and Bit

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

Arrow Function in JS

JavaScript: Deep Dive into Functions - Part 3

JavaScript string methods. [part — 3]

Callbacks, Promises and Async/Await in Javascript