2

So I need to detect IE 9. I know I should really use feature detection but I don't know what feature is causing my issue all I know is that Ie 9 is causing me issues.

I've got a work around to my issue (for those interested I asked a question about the problem here but really, it is irrelevant).

Now I want to implement this hack fix only for IE9 as this is what's causing me the headache.

So how is the best way to detect IE 9?

Community
  • 1
  • 1
Liam
  • 27,717
  • 28
  • 128
  • 190

2 Answers2

5

These IE conditionals will give you a CSS class to key-off-of:

<!--[if lt IE 7]> <html class="lt-ie10 lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie10 lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie10 lt-ie9" lang="en"> <![endif]-->
<!--[if IE 9]> <html class="lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]-->

So if you only care about IE9, you could do:

<!--[if IE 9]> <html class="ie9" lang="en"> <![endif]-->

Or, to keep with convention:

<!--[if IE 9]> <html class="lt-ie10" lang="en"> <![endif]-->

Then your JS (and CSS) could key off the HTML.lt-ie10 selector:

 if ($('HTML.lt-ie10').length) {
     //this is IE9 and older
 }
 else {
     //this is not IE9 and older (so it could be Chrome, or Safari or IE10, etc)
 }
Jeromy French
  • 11,812
  • 19
  • 76
  • 129
  • 1
    Here is more info on how to use them: http://www.positioniseverything.net/articles/cc-plus.html – pudelhund Jul 23 '13 at 15:31
  • 3
    Might as well make that last one ` `, as IE10 will treat the conditional comments as every other non-IE browser would. ;) – Derek Henderson Jul 23 '13 at 15:32
  • 1
    I found this useful to help me with the syntax btw: http://www.quirksmode.org/css/condcom.html – Liam Jul 23 '13 at 15:43
1

Using JQuery (1.8 or lower)

if ( $.browser.msie && $.browser.version == 9) {
    // Your code here
}
Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99