检测较旧的 IE 版本
我需要通过 jQuery 插件检测用户是否正在运行旧版本的 IE(IE9 可以),因此我无法控制 HTML。
我们不鼓励解析用户代理字符串并使用 $.browser.msie
。 $.support
方法也没有解决这个问题。
所以,我发现这可行,但我不确定这是否是“好的做法”。
$('body').append('<!--[if lte IE 8]><script>$("body").addClass("oldie");</script><![endif]-->');
var old_ie = $('body').is('.oldie');
您会使用此方法还是坚持解析用户代理字符串(我需要确定它是否是 IE 并获取版本号)?
I need to detect if the user is running an older version of IE (IE9 is fine) from a jQuery plugin, so I won't have control over the HTML.
We've been discouraged from parsing the user-agent string and using $.browser.msie
. The $.support
method doesn't cover the problem either.
So, I figured out that this works, but I'm not sure if it is "good practice".
$('body').append('<!--[if lte IE 8]><script>$("body").addClass("oldie");</script><![endif]-->');
var old_ie = $('body').is('.oldie');
Would you use this method or stick with parsing the user-agent string (I'll need to figure out if it's IE and get the version number)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以运行它
来检测 IE 的版本。
来源: http://ajaxian.com/archives/attack-of -the-ie-conditional-comment
然后
You can run this
to detect the version of IE.
Source: http://ajaxian.com/archives/attack-of-the-ie-conditional-comment
And then
您在问题中没有明确提及为什么您需要检测 IE9,因此一般来说以下建议成立:
您不应该检测特定浏览器/版本,而应该检测特定功能。 Modernizr 是一个获得这方面帮助的好地方。
You didn't explicitly mention in your question why you had a specific need to detect for IE9, so in general the following advice holds:
Rather than detecting for a specific browser / version, you should instead be detecting for specific features. Modernizr is a good place to start for help with this.
怎么样:
请注意,IE8 显示为 IE7
How about this:
Note that IE8 shows up as IE7
https://msdn.microsoft.com/en -us/library/ms537509%28v=vs.85%29.aspx
请参阅上面的链接,这可能是官方答案:)
简而言之,在您的 html 页面中编写以下代码。
https://msdn.microsoft.com/en-us/library/ms537509%28v=vs.85%29.aspx
See the link above, this might be the official answer :)
Briefly, code the following in your html page.