Brian.

Aren't there cases though where the browser tells you the incorrect string?
For example, I believe that older versions of IE for Mac said that they were
actually a different browser than they really were. The AOL browser also
does this same thing I think.

<!----------------//------
andy matthews
web developer
certified advanced coldfusion programmer
ICGLink, Inc.
[EMAIL PROTECTED]
615.370.1530 x737
--------------//--------->

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Brian Miller
Sent: Monday, October 09, 2006 11:12 AM
To: jQuery Discussion.
Subject: Re: [jQuery] jQuery Browser Detection


I'm inclined to disagree.

I believe that one should use object detection for cases in which they are
invoking that object for it's functionality.  A prime example is the XHR
(although MS may be messing around with that in IE7).

But, if one is best served by simply knowing what browser we are dealing
with, one should absolutely use the user agent string.  It's where the
browser vendor *tells you* what browser it is.  Why hack around, when the
vendor is telling you what you need to know?

For example: you need to apply a hack to get around one of IE6's infamous
layout bugs, when dealing with a dynamic web application.  Are you going
to test for XHR or window.clipboardData?  No, you ask the browser what
browser it is.  If it's IE6, (or IE 5.5 if the bug is there, too), code
for that instance.  We should avoid being obtuse in our code.

Summary:
1. Use object detection to detect objects, when you don't have to care
what browser you're using, as long at the object exists and will do what
you want it to.

2. Use the user agent string when you're more interested in what browser
you're actually using (by name) than you are in whether or not that
browser has a specific object available.

- Brian


> Currently, jQuery does a browser detect by checking the user agent.
> However, I think object detection would probably be a better way.
>
> This code does that by detecting unique obects on the window object.
> However, I am not sure what is unique to Safari.
>
> // Figure out what browser is being used
> jQuery.browser = {
>       safari: /webkit/.test(b),
>       opera: !!window.opera && !!window.opera.defineMagicFunction,
>       msie: !!window.clipboardData,
>       mozilla: !!window.XPCNativeWrapper
> };
>
>
> The chance of someone defining 'window.opera.defineMagicFunction',
> window.clipboardData' and 'window.XPCNativeWrapper' is virtually non
> existent (far far less likely than someone changing the user agent
> string).
>
> defineMagicFunction
> (http://www.opera.com/support/tutorials/userjs/specs/) is used by user
> scripts on Opera, clipboardData
>
(http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/clipboard
data.asp)
> is for working with the clipboard and XPCNativeWrapper
> (http://kb.mozillazine.org/XPCNativeWrapper) is used by privileged
> code (i.e. extensions) to access unprivileged code (i.e. content on a
> webpage) in a secure way.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to