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?

有帮助吗?

解决方案

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

其他提示

Using JQuery (1.8 or lower)

if ( $.browser.msie && $.browser.version == 9) {
    // Your code here
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top