使用jQuery检测IE [英] Detecting IE using jQuery

查看:110
本文介绍了使用jQuery检测IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(window).load(function () {
   if($.browser.msie && $.browser.version=="6.0") {
     // do stuff
   }
});

刚刚意识到$ .browser已在1.3中折旧。什么是检测IE的新方法,特别是IE6。

Just realized that $.browser has been depreciated in 1.3. What is the new method for detecting IE, specially IE6.

推荐答案

jQuery.browser 的jQuery文档显示以下警告。 (重点是我的。)

The jQuery documentation for jQuery.browser shows the following warning. (Emphasis is mine.)


因为 $。浏览器使用 navigator.userAgent 确定平台,易受用户欺骗或浏览器虚假陈述本身的影响。 最好尽可能完全避免特定于浏览器的代码。而不是依赖 $。browser ,最好使用 Modernizr

Because $.browser uses navigator.userAgent to determine the platform, it is vulnerable to spoofing by the user or misrepresentation by the browser itself. It is always best to avoid browser-specific code entirely where possible. Instead of relying on $.browser it's better to use libraries like Modernizr.

文档页面还说:


此属性已在jQuery 1.9中删除,只能通过jQuery.migrate插件获得。请尝试使用功能检测。

This property was removed in jQuery 1.9 and is available only through the jQuery.migrate plugin. Please try to use feature detection instead.

甚至 jQuery.support ,这是旧文档中的建议,有以下警告。 (重点是我的。)

Even jQuery.support, which was suggested from the old documentation has the following warning. (Emphasis is mine.)


表示存在不同浏览器功能或错误的属性集合。 用于jQuery的内部使用;当内部不再需要特定属性以提高页面启动性能时,可能会删除这些属性。 对于您自己项目的功能检测需求,我们强烈建议您使用外部库,例如 Modernizr 而不是依赖于 jQuery.support 中的属性。

A collection of properties that represent the presence of different browser features or bugs. Intended for jQuery's internal use; specific properties may be removed when they are no longer needed internally to improve page startup performance. For your own project's feature-detection needs, we strongly recommend the use of an external library such as Modernizr instead of dependency on properties in jQuery.support.

以前的文档 jQuery.support 报告了以下属性和值。

The previous documentation for jQuery.support reported the following properties and values.


  • $ .support.boxmodel 在IE 6和7中是 false

  • <对于IE 6,7和8,code> $ .support.cssFloat 是 false ;在IE 9中它是 true

  • $ .support.leadingWhitespace is IE 6,7和8的 false

  • $ .support.objectAll 目前 false

  • $.support.boxmodel is false in IE 6, and 7.
  • $.support.cssFloat is false for IE 6, 7 and 8; it is true in IE 9.
  • $.support.leadingWhitespace is false for IE 6, 7, and 8.
  • $.support.objectAll is currently false for IE 6, 7, and 8.

这篇关于使用jQuery检测IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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