How would I go about doing a detect to see if the browser is either firefox, ie (but not ie6), opera, chrome or safari by using feature detection?
-
1What are you trying to determine? "Feature detection" is used to say, if it will support this, do that, if not, fallback...the point is to not care which browser. Given that, what are you determining the browser for? – Nick Craver Feb 10 '10 at 02:00
-
Thanks, I might be going about this the wrong way then. But I have been told to put a warning up on the site if someone is not using one of the above mentioned sites. I thought JS could be a way of doing this, but with $.browser being deprecated I thought feature detection might solve this problem. – Colin Feb 10 '10 at 02:30
-
If your requirements say you must include an "old browser" notice, than you should check the user-agent with either `$.browser` or server-side code. Feature detection is not a reliable way of detecting browsers. – Joel Feb 10 '10 at 02:57
-
Cool thanks for the help, I have currently got $.browser doing the detection but thought this was bad practice (and probably is) but I can't find any other way of doing it. – Colin Feb 10 '10 at 20:25
3 Answers
Feature detection is not supposed to tell you which browser the user is using. It is meant to tell you if the browser can handle what you need to do.
So for instance, if you need to support ActiveX, you might check
if(ActiveXObject) { ... }
This is better than checking if the browser is IE because some other browser (current or future) might support ActiveX too.
A more useful example may be text node checking when traversing a node list.
if (!el.tagName || el.tagName != expectedTagName)
el = el.nextSibling; // skip the text node

- 12,315
- 4
- 41
- 45

- 19,175
- 2
- 63
- 83
I was searching for an answer, thinking perhaps someone had solved my issue. Like many, I ended up writing my own:
try {
if (ActiveXObject != undefined) {
alert("we have activex");
}
}
catch (err)
{
alert(err.message);
}
You will, of course, want to customize your implementation. My example just shows the base logic. HTH!

- 751
- 9
- 20
For Safari: I'm going the server side route, ie using Chris Schuld's Browser.php; apart from the http user agent there's very little documentation about Safari feature detection.

- 1