Como obtener el nombre del navegador por medio de #javascript #js

Para obtener cual es el navegador por el cual entra el usuario a nuestro sitio web, anexo la siguiente función la cual regresa un entero dependiendo el navegador:


//1= Opera
//2= Firefox
//3= Safari
//4= IE
//5= Edge
//6= Chrome
//7= Blink
function cualNavegador(){
	// 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;

	// Blink
	var isBlink = (isChrome || isOpera) && !!window.CSS;

	if(isOpera)return 1;
	if(isFirefox)return 2;
	if(isSafari)return 3;
	if(isIE)return 4;
	if(isEdge)return 5;
	if(isChrome)return 6;
	if(isBlink)return 7;

	return 0; //sin identificar
}

Autor: Héctor de León

Desarrollador de software, lector compulsivo.