Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect all versions of IE with Javascript? How?

Very new to web development, bear with me.

I want to check if the browser used is IE (all versions).

I need to change CSS if IE is detected.

Point me in right direction please.

like image 426
Ido Turg Avatar asked Mar 19 '15 09:03

Ido Turg


People also ask

How do you check IE version?

In the upper corner of Internet Explorer, select the Tools button, and then select About Internet Explorer. Open Internet Explorer, at the upper right, select the Tools button, and then choose About Internet Explorer.

What version of JavaScript does Internet Explorer use?

Support for recent versions of JavaScript. Internet Explorer 11 doesn't support JavaScript versions later than ES5. If you want to use the syntax and features of ECMAScript 2015 or later, or TypeScript, you have two options as described in this article.

Does IE support JavaScript?

Internet Explorer Click Tools > Internet Options. Click the Security tab > Custom Level. In the Scripting section, click Enable for Active Scripting.

How does IE11 detect browser?

document. documentMode; // true on IE11 // false on Edge and other IEs/browsers. this will return true only for ie11.


1 Answers

This is the JS I use

(function detectIE() {
  var ua = window.navigator.userAgent;
  var msie = ua.indexOf('MSIE ');
  var trident = ua.indexOf('Trident/');
  var edge = ua.indexOf('Edge/');
  if (msie > 0) {
    // IE 10 or older 
    //Do some stuff
  }
  else if (trident > 0) {
    // IE 11 
    //Do some stuff
  }
  else if (edge > 0) {
    // Edge 
    //Do some stuff
  }
  else
    // other browser
    return false;
})();
like image 138
U r s u s Avatar answered Oct 05 '22 23:10

U r s u s