Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to check for IE less than 9 in JavaScript without library

What would be your fastest, shortest (best) way to detect browser which is IE and version less than 9 in JavaScript, without using jQuery or any add-on libraries?

like image 594
bcm Avatar asked Apr 07 '11 01:04

bcm


People also ask

How do I check my IE browser?

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.

Does IE 11 support 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. You can also combine these two techniques.

What version of JavaScript does Internet Explorer use?

According to Wikipedia, IE8 only supports Javascript 1.5. So they are saying IE8 completely ignores Javascript versions 1.6, 1.7, 1.8 and 1.9.

Does Internet Explorer use JavaScript?

As with most modern browsers, Internet Explorer supports JavaScript, which is enabled by default to allow users view dynamic interactions like display ads and animations on web pages.


1 Answers

Javascript

var ie = (function(){      var undef,         v = 3,         div = document.createElement('div'),         all = div.getElementsByTagName('i');      while (         div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',         all[0]     );      return v > 4 ? v : undef;  }()); 

You can then do:

ie < 9 

By James Panolsey from here: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments

like image 147
Mike Lewis Avatar answered Sep 19 '22 16:09

Mike Lewis