Skip to main content

Get Internet Explorer (IE) version number. Support for new IE navigator.userAgent.

/**
   * Get IE version
   *
   * IE11 no longer reports as `MSIE` in `navigator.userAgent`. This function
   * handles both cases.
   *
   * @see [Compatibility changes in IE11](http://msdn.microsoft.com/en-us/library/ie/bg182625(v=vs.110).aspx#uaString)
   * @author Jon LaBelle
   *
   * @return {Number} The IE version number, or -1 for no match.
   */

  function getIEVersion() {
    var ua = navigator.userAgent,
      browserName = navigator.appName;

    if (browserName == 'Microsoft Internet Explorer' || browserName ==
      'Netscape') {
      // ie <= v10
      var ielte10 = ua.match(/MSIE ([0-9]{1,}[.0-9]{0,})/);
      if (ielte10 != null) {
        return parseFloat(ielte10[1]);
      }
      // ie >= v11
      var iegte11 = ua.match(/Trident\/.*rv:([0-9]{1,}[.0-9]{0,})/);
      if (iegte11 != null) {
        return parseFloat(iegte11[1]);
      }
    }
    return -1;
  }