Detecting Browsers on Desktop and Mobile : Edge, Opera, Chrome, Safari, Firefox, IE

Last Updated On Thursday 9th Sep 2021

Detect Browser JavaScript

  • The Navigator.userAgent read-only property returns the user agent string for the current browser.

Syntax

	navigator.userAgent;
	
	function getBrowserType() {
  if (navigator.userAgent.indexOf("Edge") > -1 && navigator.appVersion.indexOf('Edge') > -1 )) {
    return "Edge";
  } else if (navigator.userAgent.indexOf("MSIE 7") > -1) {
    return "MSIE 7";
  } else if (navigator.userAgent.indexOf("MSIE 8") > -1) {
    return "MSIE 8";
  } else if (navigator.userAgent.indexOf("MSIE 9") > -1) {
    return "MSIE 9";
  } else if (navigator.userAgent.indexOf("MSIE 10") > -1) {
    return "MSIE 10";
  } else if (navigator.userAgent.indexOf("rv:11.0") > -1) {
    return "rv:11.0";
  } else if (navigator.userAgent.indexOf("Firefox") > -1) {
    return "Firefox";
  } else if (navigator.userAgent.indexOf("Chrome") > -1) {
    return "Chrome";
  } else if (navigator.userAgent.indexOf("Opera") > -1 || navigator.userAgent.indexOf('OPR') != -1) {
    return "Opera";
  } else {
    return "Unknown";
  }
}

	

JavaScript Browser Detect

	console.log(getBrowserType())

// Chrome
// Firefox
	

Reference

Navigator.userAgent Link