使用 jQuery 检测 IE

发布于 2024-08-15 05:14:01 字数 199 浏览 9 评论 0原文

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

刚刚意识到 $.browser 在 1.3 中已经贬值了。检测 IE(特别是 IE6)的新方法是什么?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叫嚣ゝ 2024-08-22 05:14:02

文档中的热门信息:我们建议不要使用此属性,请尝试使用功能检测(请参阅 jQuery.支持)。

hot from the documentation: We recommend against using this property, please try to use feature detection instead (see jQuery.support).

肤浅与狂妄 2024-08-22 05:14:02

显示浏览器信息

jQuery.each( jQuery.browser, function( i, val ) {
$( "<div>" + i + " : <span>" + val + "</span>" )
.appendTo( document.body );
});

警告正在使用的 IE 渲染引擎的版本。除非包含 jQuery Migrate 插件,否则无法在 jQuery 1.9 或更高版本中工作。

if ( $.browser.msie ) {
alert( $.browser.version );
}

Show the browser Information

jQuery.each( jQuery.browser, function( i, val ) {
$( "<div>" + i + " : <span>" + val + "</span>" )
.appendTo( document.body );
});

Alert the version of IE's rendering engine that is being used. Will not work in jQuery 1.9 or later unless the jQuery Migrate plugin is included.

if ( $.browser.msie ) {
alert( $.browser.version );
}
以往的大感动 2024-08-22 05:14:01

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

由于 $.browser 使用 navigator.userAgent 来确定平台,它很容易受到用户欺骗或浏览器误传本身。 最好尽可能完全避免浏览器特定的代码。与其依赖 $.browser,不如使用 Modernizr 这样的库。

文档页面还说:

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

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

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


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

  • $.support.boxmodel 在 IE 6 和 7 中为 false
  • $.support.cssFloatfalse IE 6、7 和 8;在 IE 9 中为 true
  • 在 IE 6、7 和 8 中,$.support.leadingWhitespacefalse
  • $.support对于 IE 6、7 和 8,.objectAll 目前为 false

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

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.

The documentation page also says:

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

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

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.

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

  • $.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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文