-2

How to know name of browser javascript , I want to know if browser is IE or not, I tried to use this

navigator.appName

but this code it give the same result with

IE11, Firefox, Chrome and Safari returns "Netscape"

How can i know IE ? ( I don,t care for versions )

  • possible duplicate of [Browser detection in JavaScript?](http://stackoverflow.com/questions/2400935/browser-detection-in-javascript) – Sascha Wolf Feb 26 '15 at 08:37
  • They all return Netscape as there app name now, look at: [detecting ie](https://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx) – atmd Feb 26 '15 at 08:38
  • @atmd `if ( ver >= 8.0 ) msg = "You're using a recent copy of Internet Explorer."` Only if IE8 was recent. – MisterBla Feb 26 '15 at 08:44
  • possible duplicate of [jQuery: check if user is using IE](http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie) – Vladu Ionut Feb 26 '15 at 08:47

2 Answers2

1

Here are all the information that you need (but is not the first time that a similar question was done here):

var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName  = navigator.appName;
var fullVersion  = ''+parseFloat(navigator.appVersion); 
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
   browserName = "Opera";
   fullVersion = nAgt.substring(verOffset+6);
   if ((verOffset=nAgt.indexOf("Version"))!=-1) 
     fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
   browserName = "Microsoft Internet Explorer";
   fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome" 
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
   browserName = "Chrome";
   fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version" 
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
   browserName = "Safari";
   fullVersion = nAgt.substring(verOffset+7);
   if ((verOffset=nAgt.indexOf("Version"))!=-1) 
     fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox" 
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
    browserName = "Firefox";
    fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent 
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) {
    browserName = nAgt.substring(nameOffset,verOffset);
    fullVersion = nAgt.substring(verOffset+1);
    if (browserName.toLowerCase()==browserName.toUpperCase()) {
       browserName = navigator.appName;
    }
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
    fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
    fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
    fullVersion  = ''+parseFloat(navigator.appVersion); 
    majorVersion = parseInt(navigator.appVersion,10);
}

document.write(''
                +'Browser name  = '+browserName+'<br>'
                +'Full version  = '+fullVersion+'<br>'
                +'Major version = '+majorVersion+'<br>'
                +'navigator.appName = '+navigator.appName+'<br>'
                +'navigator.userAgent = '+navigator.userAgent+'<br>');
Giacomo Alessandroni
  • 666
  • 1
  • 14
  • 27
0
 var IE = (function msieversion() {

        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");

        if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer, return version number
          return true;
        else                 // If another browser, return 0
          return false;

   return false;
})();
    var SAFARI = navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Windows') > -1 && navigator.userAgent.indexOf('Chrome') == -1; // Safari for Windows
    var ANDROID = navigator.userAgent.toLowerCase().indexOf("android")  > -1;
    var IOS = ( function() {
           var userAgent = navigator.userAgent || navigator.vendor || window.opera;
           if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
          {
            return true;
          }
          return false;
        })();
Vladu Ionut
  • 7,407
  • 1
  • 15
  • 28