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

react, etc.

How I created a blog using Next.js and MDX

React 3030 — Episode 2 (Project Folder Structure)

How to Easily Share Data Between Two Angular Components

Back To The Basics: Using React + Flow Pt.2

Node Weekly Issue 25

Angular Azure — Auth, CI/CD, IaC, and Serverless — Part 2

Constructor

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