How do I use JQuery.support to check if the browser is Firefox?

后端 未结 1 1530
轻奢々
轻奢々 2021-01-21 19:43

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 b

相关标签:
1条回答
  • 2021-01-21 19:49

    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).

    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.

    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/feature-detection-state-of-the-art-browser-scripting http://www.nczonline.net/blog/2006/11/16/browser-detection-versus-feature-detection/

    0 讨论(0)
提交回复
热议问题