Detecting Internet Explorer with JavaScript

20 May 2019

Detecting Internet Explorer is an important part of some projects, especially when implementing any kind of progressive enhancement technique. Unfortunately, Microsoft changes the User Agent string to make it look ike something else. Here’s a quick workaround to detect IE:

function isIE() {
  var ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
  var msie = ua.indexOf('MSIE '); // IE 10 or older
  var trident = ua.indexOf('Trident/'); //IE 11
  return (msie > 0 || trident > 0);
}