如何使用JQuery.support检查浏览器是否为Firefox? [英] How do I use JQuery.support to check if the browser is Firefox?

查看:107
本文介绍了如何使用JQuery.support检查浏览器是否为Firefox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最新的jQuery中似乎不推荐使用jQuery.browser.该文档建议我使用jQuery.support.我应该使用哪些支持测试来检查当前浏览器是否为Firefox?

It seems that jQuery.browser is deprecated in the latest jQuery. The doc recommends that I use jQuery.support. Which of the support tests should I use to check if the current browser is Firefox?

推荐答案

您缺少支持"方法的要点.您无需检查用户是否正在使用Firefox.您检查浏览器是否支持"您尝试执行的任何DOM操作.这称为功能检测",与浏览器检测"(您要尝试的操作)相比,它更受欢迎.

You are missing the point of the 'support' method. You don't check if user is using Firefox or not. You check whether the browser 'supports' whatever DOM manipulation you are trying to do. This is called 'feature detection' which is preferred compared to 'browser detection'(what you are trying to do).

例如假设您要验证浏览器是否可以呈现包含"opacity"的CSS,因此可以使用jquery.support.opacity属性.

E.g. let's say you want verify whether the browser can render your CSS which contains 'opacity', so you use the jquery.support.opacity property.

那么您为什么要进行特征检测"?很简单,您可以编写将来兼容的跨浏览器脚本.

So why would you want to do 'feature detection'? Simple, you can write cross browser scripts which are future compatible.

比方说,您检查"Firefox"并应用了一些精心设计的DOM/CSS效果.如果下一版本的Firefox破坏了您所依赖的特定DOM/CSS功能,该怎么办?您将不得不返回并更新您的脚本.但是,如果您使用功能检测",则您的代码将成为将来抵御此类更改的证明.

Let's say that you check for 'Firefox' and apply some elaborate DOM/CSS effects. What if the next version of Firefox breaks the particular DOM/CSS feature you were relying on? You will have to go back and update your script. But if you used 'feature detection', your code will be future proof against such changes.

现在,我不建议您能够满足所有需求使用功能检测",但请考虑一下要使用功能检测还是浏览器检测.

Now, I am not suggesting that you will be able to use 'feature detection' for all your requirements, but put some thought about whether you want to use feature detection or browser detection.

还有几个值得阅读的链接:

Few more links worth reading:

http://peter.michaux. ca/articles/功能检测器浏览器脚本的最新状态 http://www.nczonline.net/blog/2006/11/16/browser-detection-versus-feature-detection/

这篇关于如何使用JQuery.support检查浏览器是否为Firefox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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