在没有特征检测的情况下检测IE9 [英] Detect IE9 without feature detection

查看:62
本文介绍了在没有特征检测的情况下检测IE9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要检测IE 9.我知道我应该使用特征检测但我不知道导致我的问题的是什么功能所有我知道的是,即9引起了我的问题。

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我已经解决了我的问题(对于那些感兴趣的人我问了一个关于这个问题的问题这里但实际上,这是无关紧要的。)

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

现在我想为IE9实现这个 hack 修复因为这是让我头疼的原因。

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

那么检测IE 9的最佳方法是什么?

So how is the best way to detect IE 9?

推荐答案

这些IE条件将为您提供一个关键的CSS类:

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]-->

所以如果你只关心IE9,你可以这样做:

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]-->

然后你的JS(和CSS)可以关闭HTML.lt-ie10选择器:

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

这篇关于在没有特征检测的情况下检测IE9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆