tags:

views:

1009

answers:

2

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?

+1  A: 

I thought John Resig said that browser would be staying in JQuery since it useful for CSS coding and we could keep using it?

Corv1nus
As far as I know, I haven't said that. It's fundamentally very important that you do feature testing wherever possible - including attempting to do it with CSS. jQuery.browser is mostly being left in for backwards compatibility (if we were to remove it it would break a lot of plugins).Perhaps you were thinking of the case where I was saying that it's fundamentally very hard to determine if some CSS is actually having the desired effect. (e.g. does color: blue actually make the text blue). It's likely not possible to feature test that.
John Resig
+5  A: 

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/

SolutionYogi
I'm not so sure feature detection makes your app future proof. What if the feature exists but becomes buggy in some way?
Nosredna
Well, it won't make it 100% foolproof. But the feature detection code will be more resilient compared to the browser detection code.
SolutionYogi
Maybe. I'm waiting to see if that's true. I had one case where the flot charting application screwed up on filled charts on Opera only before a certain revision. There was no good way to test for that. I had to explicitly test for Opera and a revision. I think that a lot of people are embracing feature detection with little evidence that it will save them. I think what's more likely is that browsers will work with jQuery BECAUSE jQuery is so popular that it will be well-tested against.
Nosredna
As I wrote in my original post, it's not possible to use feature detection in all circumstances [e.g. you can't check if browser supports transparent PNGs.] And yes, if browser vendors try to support jQuery and if you use jquery.support, you are covered automatically as against if you used jQuery.browser.
SolutionYogi
Didn't mean to argue with you. I'm just skeptical about whether feature detection is the future-proofing that people desire. Browser compatibility is tough no matter what. For example, Mobile Safari doesn't return a mousedown message until the mouseup happens. How do you detect that? I think a lot of feature detection is veiled browser detection.
Nosredna