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

查看:20
本文介绍了使用 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 文档 code>jQuery.browser 显示以下警告.(重点是我的.)

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

由于$.browser 使用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.
  • $.support.cssFloat 对于 IE 6、7 和 8 是 false;在 IE 9 中是 true.
  • $.support.leadingWhitespace 对于 IE 6、7 和 8 是 false.
  • $.support.objectAll 当前对于 IE 6、7 和 8 为 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天全站免登陆