1//gets the type of browser
2function detectBrowser() {
3 if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
4 return 'Opera';
5 } else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
6 return 'Chrome';
7 } else if(navigator.userAgent.indexOf("Safari") != -1) {
8 return 'Safari';
9 } else if(navigator.userAgent.indexOf("Firefox") != -1 ){
10 return 'Firefox';
11 } else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
12 return 'IE';//crap
13 } else {
14 return 'Unknown';
15 }
16}
1var sBrowser, sUsrAg = navigator.userAgent;
2
3// The order matters here, and this may report false positives for unlisted browsers.
4
5if (sUsrAg.indexOf("Firefox") > -1) {
6 sBrowser = "Mozilla Firefox";
7 // "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
8} else if (sUsrAg.indexOf("SamsungBrowser") > -1) {
9 sBrowser = "Samsung Internet";
10 // "Mozilla/5.0 (Linux; Android 9; SAMSUNG SM-G955F Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/9.4 Chrome/67.0.3396.87 Mobile Safari/537.36
11} else if (sUsrAg.indexOf("Opera") > -1 || sUsrAg.indexOf("OPR") > -1) {
12 sBrowser = "Opera";
13 // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.106"
14} else if (sUsrAg.indexOf("Trident") > -1) {
15 sBrowser = "Microsoft Internet Explorer";
16 // "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Zoom 3.6.0; wbx 1.0.0; rv:11.0) like Gecko"
17} else if (sUsrAg.indexOf("Edge") > -1) {
18 sBrowser = "Microsoft Edge";
19 // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
20} else if (sUsrAg.indexOf("Chrome") > -1) {
21 sBrowser = "Google Chrome or Chromium";
22 // "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36"
23} else if (sUsrAg.indexOf("Safari") > -1) {
24 sBrowser = "Apple Safari";
25 // "Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1 980x1306"
26} else {
27 sBrowser = "unknown";
28}
29
30alert("You are using: " + sBrowser);