0

I've tried the following solutions but it always tells me that the browser is NOT internet explorer even if I am using Internet Explorer 11.

Note that the following solutions are what I saw in the net, but unfortunately, none of them works. I don't understand why they are checking for "Trident" whereas when I tried to alert the userAgent in the IE11 screen, I don't see any word "Trident".

ATTEMPT 1:

function detectIE() {
  var ua = window.navigator.userAgent;

  var msie = ua.indexOf('MSIE ');
  if (msie > 0) {
    // IE 10 or older => return version number
    return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
  }

  var trident = ua.indexOf('Trident/');
  if (trident > 0) {
    // IE 11 => return version number
    var rv = ua.indexOf('rv:');
    return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
  }

  var edge = ua.indexOf('Edge/');
  if (edge > 0) {
    // Edge (IE 12+) => return version number
    return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
  }

  // other browser
  return false;
}

ATTEMPT 2:

function isIE() {
  ua = navigator.userAgent;
  /* MSIE used to detect old browsers and Trident used to newer ones*/
  var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;

  return is_ie; 
}

ATTEMPT 3:

const isIEOrEdge = /msie\s|trident\/|edge\//i.test(window.navigator.userAgent)
iPhoneJavaDev
  • 821
  • 5
  • 33
  • 78
  • https://stackoverflow.com/questions/21825157/internet-explorer-11-detection – epascarello Jul 10 '19 at 13:25
  • If you can `alert()` the actual `userAgent` value, can't you write your own regular expression to match it? Or at least include it in the question. – Pointy Jul 10 '19 at 13:25
  • Actually, i'm not good at regex. also, how can I be sure if that expression will be correct? Do i install other browser and alert on each? – iPhoneJavaDev Jul 10 '19 at 13:26

0 Answers0