Javascript User Agent Detection

Thursday June 3rd, 1999

Eric Krock of Netscape wrote to me and asked that I make this request to mz's readers:

Apparently there are many people out there using User Agent detection scripts that not only fail to detect IE5 and Mozilla (what will be Communicator5), but fail to detect that scripts meant for IE4 and Nav4 would also work in the 5.0 browsers. Netscape has created a more up-to-date client sniffer, and is requesting that people mention it in the signature area of their email messages - sort of a grass-roots way of getting the message out that User Agent detection has to be updated. Here's the recommended message:

Is your JavaScript ready for Nav5 and IE5?
Get the latest JavaScript client sniffer at

I've enabled the link in the sig above solely so you can visit the page and see it for yourself...

#1 Re:Javascript User Agent Detection

by reluv

Thursday June 3rd, 1999 9:57 AM

Reply to this message

We shouldn't need a sniffer at all. W3C has to "enforce" their recommendation (is there?) concerning styles, layers, DOM of all levels... Netscape and Microsoft should go towards the users, not the money.

#2 Re:

by Jake <>

Thursday June 3rd, 1999 10:49 AM

Reply to this message

Actually, the sniffer is more for detecting versions of the browser, although it obviously is plenty capable of detecting whether it's IE for NS (or any of the others). Even if IE and NS were 100% compitable, version 5 would have more features than 4 (at least we would hope, never know w/MS) so the sniffer would still be needed.

Don't get me wrong, I agree that it would be nice if IE would support standards (especially the ones they wrote), but the Mozilla programers can only make Mozilla complient, not IE (although they're even trying to do the using ActiveX, aren't they talented....)

#3 Re:Javascript User Agent Detection

by WillyWonka

Thursday June 3rd, 1999 3:58 PM

Reply to this message

Is there any standard way to detect if a browser is fully <insert standard here> compliant?

#4 Re:Javascript User Agent Detection

by Kevin Berkheiser

Thursday June 3rd, 1999 4:38 PM

Reply to this message

I actually started using it a few weeks ago. It works pretty good. The only problem is that Opera minor revision numbers are not detected because for some reason the Opera developers decided not to put it in the navigator.appversion result but instead in the navigator.useragent.

#5 Re:Javascript User Agent Detection

by zontar

Thursday June 3rd, 1999 4:46 PM

Reply to this message

Gag me.

I've been using (and telling other people to use) OBJECT detection instead of browser detection for the last couple of years. That solves 90% of the problem right there, avoids long strings of &&'ed statements and is backward- AND forward-compatible by definition. As a result, my JS and DHTML pages are ALREADY ready, and have been, since I wrote them...


#6 Re:Javascript User Agent Detection

by Kovu <>

Thursday June 3rd, 1999 5:39 PM

Reply to this message

They mention Opera 3.0. I wish them luck, but I honestly think they're going to really get mauled by Netscape 5.0, much more so than IE, (which at least has Windows users who would be quicker removing their own tonsils than trying to figure out how to in some way NOT use IE for something).

#7 Re:Javascript User Agent Detection

by mozineAdmin

Thursday June 3rd, 1999 5:57 PM

Reply to this message


If you get a moment, you should read that page at Netscape (the page with the UA detection code). The describe why they couldn't use object detection - it didn't work in IE3.

#8 Re:Javascript User Agent Detection

by Tekhir

Thursday June 3rd, 1999 9:18 PM

Reply to this message

Opera is still providing a lot of features to Win 3.x platform and since there is no "offficial" support from Netscape for that platform anymore they'll do alright.

#9 Re:Javascript User Agent Detection

by arielb

Thursday June 3rd, 1999 9:32 PM

Reply to this message

win 16 is only 10% of their market. But Opera will get mauled if they don't compete in the standards dept.

#10 Re:Javascript User Agent Detection

by Maxxy

Thursday June 3rd, 1999 11:28 PM

Reply to this message

I used object detection for IE 3 especially for rollovers (detecting the Image object). What's the problem?

#11 Re:Javascript User Agent Detection

by Maxxy

Friday June 4th, 1999 12:29 AM

Reply to this message

I used object detection for IE 3 especially for rollovers (detecting the Image object). What's the problem?

#12 Re:Javascript User Agent Detection

by _Dan

Friday June 4th, 1999 12:56 AM

Reply to this message

One instance where object detection completely fails is in the case of plug-in detection!!! You should for example be able to use something like this

if(navigator.plugins){ if(navigator.plugins["ShockWave"]){ // User has shockwave go to shockwave site } else{ // User doesn't have shockwave go to non-shocked site } } else{ // No plugin detection for this browser, ask the user!!! }

Now in a perfect world any browser that supported the plugins array would pass the object detection, and any one that didn't would fail allowing you to ask the user. However MS thought it would be clever, and instead of just skiping the pluggins array they pretend it works but simply return an empty collection. Inturn it passes the object detection, but fails the plugin detection because of lack of support.

#13 Re:Javascript User Agent Detection

by zontar

Friday June 4th, 1999 6:38 PM

Reply to this message

Heheh, just thought I'd see if I could get a rise out of people. ;-)

Yes, I have read the linked page @ Yes, I realize there are times when object detection fails -- for instance, doesn't work correctly in NN2.X for Unix and Mac (but let's be honest here -- just how many of you still bother making that second call to the open() method to get around it? I'll bet there's not too many hands raised...), MSIE4.0/Mac doesn't support dynamic clipping of CSS layers, etc. There is also the problem of dealing with MSIE's "pretend" support of the plugins array -- for which, in the case of Flash, for instance, you wind up checking for the existence of several elements in the plugins array, and document.write()ing an EMBED tag into the page for MSIE. (Although, strictly speaking, that's still object detection rather than userAgent detection, n'est-ce pas?)

The point I was trying to make is that, IMNSHO, in many cases, object detection works just fine, and there are (& going to be) a lot of broken pages just because people detected specifically for MSIE4 instead of checking for document.all (I've hit several of them myself when using MSIE5). The document.images detection mentioned above is another case in point.

It just irks me to see people hollering about checking for every agent/version/platform under the sun in cases where it's not necessary, that's all. Almost as much as it irks me that people can't seem to see ahead far enough to use ">=" instead of "=". Believe me, I'm not knocking Netscape for trying to raise a little consciousness in this regard, and trying to avoid "This Netscape 5 is sure a crappy browser" when it's the fault of the aforementioned people who didn't bother to look ahead past the browser version they were using when they posted their pages...

Having susserated my little susseration, I will now slither back under the rock whence I came, that I might avoid the heat of further flames from the Mighty MozAdmin... <grin>

#14 Re:Javascript User Agent Detection

by Anon

Friday June 4th, 1999 11:40 PM

Reply to this message

Actually the document.all and document.layers test are the most widely used method of checking for 4+ browser, but they are also the cause of many problems!!! For example the Mac and PC versions of IE4+ are different so using a simple document.all check will not do you any good. Not only that but IE4 and IE5 have compatibility issues that cause a simple document.all check to fail. Object checking is great for some things (like document.images) but browser checking is an inevitable part of writing JavaScript and will be for some time to come.

#15 Re:Javascript User Agent Detection

by Anon

Saturday June 5th, 1999 6:39 AM

Reply to this message

so? you do a if(document.all), then you do a if(navigator.appVersion.indexOf("Mac")==-1) in the parts concerning dynamic clipping or whatever... as if there's anyone who actually USES IE/Mac...

what are the IE 4 vs 5 compatibility problems you cite? and who's going to bother authoring for either one once NS 5 comes out anyway? heheheheheheheh

even if theres a devil or two in the details i think zontar does make a point. otherwise you guys wouldnt be getting so defensive about it.