Detect Browser in Javascript

---
date: Jan 18, 2018
tags:
- Javascript
language: English
---
This post is more than 5 years old. If this is a technical post, the post will most likely not working, but feel free to try it and see if it works.

Here is a easy way to find out what browser the user is using when they browse this page; supports 6 most commonly used browsers, but it might not work on mobile since operating systems like iOS will force browser to use their core.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';

// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || (function (
p) {
return p.toString() === "[object SafariRemoteNotification]";
})(!window['safari'] || safari.pushNotification);

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/ false || !!document.documentMode;

// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;

// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;

var data = isOpera ? 'opera' :
isFirefox ? 'firefox' :
isSafari ? 'safari' :
isChrome ? 'chrome' :
isIE ? 'ie' :
isEdge ? 'edge' :
"browser";

Comments

Navigation