Question

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?

Était-ce utile?

La solution

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)
 }

Autres conseils

Using JQuery (1.8 or lower)

if ( $.browser.msie && $.browser.version == 9) {
    // Your code here
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top