16

I have codes $.browser to detect the browser and upon the result some layout style is based. but now with ie 11, $.browser would give mozilla v.11. any suggestion to repair ?

therion
  • 183
  • 1
  • 1
  • 6
  • 4
    I thought IE11 was up-to-date enough with modern styling that you could just use whatever styles you were using? – Waleed Khan Nov 20 '13 at 06:42
  • actually the gradient of mozilla style doesn't work. but the legacy code using $.browser just detect ie11 as mozilla. and i can't remove the $.browser. – therion Nov 20 '13 at 07:00
  • Just so you're aware, jQuery.browser was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. They recommend you use feature detection instead. See http://api.jquery.com/jQuery.browser/ – Olly Hodgson Dec 13 '13 at 12:16
  • here's the best solution I've found: http://stackoverflow.com/a/20201867/2047385 if (Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) { // is IE11 } – xorcus May 20 '15 at 12:57

2 Answers2

34

Try this:

var isIE11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
alert(isIE11);

EDIT:

Editted in a regex fix, taken from the comments. This fix works in the current version of IE11 as of 2/17/2014.

War10ck
  • 12,387
  • 7
  • 41
  • 54
swt
  • 417
  • 4
  • 3
  • thanks. that's probably the only way – therion Nov 20 '13 at 07:16
  • 2
    Fixed: `!!navigator.userAgent.match(/Trident.*rv\:11\./);` – pstadler Jan 27 '14 at 11:01
  • Or `!!navigator.userAgent.match(/Trident\/7\./);` because it can send something along the line of `Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)` – DitherSky Sep 05 '14 at 17:12
  • 1
    here's the best solution I've found: http://stackoverflow.com/a/20201867/2047385 if (Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) { // is IE11 } – xorcus May 20 '15 at 12:59
5

That last one was correct.

Example:

To apply a body style for IE only for IE7 and above (including 10+11...)

Copy/Paste this code inside the <head></head> tag:

<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>//<![CDATA[ 
$(function(){
      if(navigator.userAgent.match(/Trident\/7\./)) {
          $('body').addClass('if-ie');
     }


});//]]>
</script>
user3253525
  • 51
  • 1
  • 2