D Silver

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromD Silver
ToMe
Subjectbrowser sniffing?
Date29 April 2003 4:40 AM
Hi, I just thought that this subject would be a good
one to include on your website.

Also, I'm very confused on the whole sniff thing...
I'm reading and reading and am finding no definative
method to sniff a browser.

Of the three methods I've read:
1) old navigator objects 
2) document objects
3) Doc Content type

all three are downplayed and then you're told to use
them...???

So far the most consistent sniff style I've read over
and over agian is to use the navigator object.  But,
on NS's website they give an extremely good set of
reasons to not do it this way, then they go on to say
that it will still work.  As well they go on about how
checking for objects isn't correct either.

I don't plan on using XHTML just yet since browsers
still seem to render flwaed syntax anyway..so I see no
point just yet.

Anyway, my Question. Do you know the proper standards
compliant way to sniff?
You seem to know what you're doing, you're website has
really good scripts and pretty advanced techniques
that I've found nowhere else.

thanks
FromMe
ToD Silver
SubjectRe: browser sniffing?
Date29 April 2003 8:52 AM
There is a section on how to browser sniff on the website, but I try to
avoid telling people to use it, due to the fact that sniffing usually
blocks out minor browsers, and needs to be updated regularly.

Using sniffing implies that you know how all of the many browsers work, and
it is far better to detect how browsers work using if(someObject.someMethod)
than sniffing for a browser and assuming you know how it works.

Still, there are some times when a sniff is unavoidable, such as when
HotJava claims to support document.layers, but does not, or when browsers
support different implementations of the same property as with obtaining
the mouse position (event information section).

It needs to be done properly. There is NO standards compliant way to sniff
(although the official recommendation is to use the userAgent, even though
it is not part of any W3C or ECMA standard), as in order for minor browsers
to be allowed to gain access to badly written sniffing sites, they allow
the users to change the userAgent string. The page I have provided gives
reliable ways to sniff in spite of these, but will need updating with every
release of any JavaScript 1.2 browser.

see my JavaScript libraries page
http://www.howtocreate.co.uk/jslibs/
subsection Sniffer Demo
http://www.howtocreate.co.uk/tutorials/jsexamples/sniffer.html

It gives you a header file that you can use that detects all major and
minor DHTML browsers. It will even work with XHTML browsers, you just need
to remove the language="javascript1.2" attribute from the script tag.

Hope this helps,


Tarquin
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.