02.21.09
A Note to Web Developers
If any of your scripts (or any of the external JavaScript files your site may use) contain any of the text
- http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
- Ultimate client-side JavaScript client sniff
- The Ultimate JavaScript Client Sniffer
here’s a tip1 for you: You’re Doing It Wrong.
Sincerely,
Everyone using the Internet since 2002
1 Here’s an additional tip, free of charge: the method you are using is not only wrong, but it’s also overly complex and unmaintainable, and you are misidentifying current, fully-capable browsers and annoying your users.2 ↩
2 A third tip, also offered free of charge: if you don’t know where to find information about properly detecting which features of various web specifications your users’ browsers support, you can start by reading this article about feature detection and rendering engines. ↩
02.22.09 at 4:17 am
lol.
Which one did you hit today ?
02.22.09 at 9:39 am
I did a ‘how to detect firefox’ search in google, and almost all of them (at least the first 10 i looked at) suggest to look at the firefox part of the user agent, and not the gecko part.
What about tracking those sites down as well, and suggest them to change there sample code into detecting gecko instead of firefox? That way i’m sure many would-be web developers will pick up the good practice.
ps. didn’t feel like spamming bug 334967, so i post this here.
02.22.09 at 2:17 pm
Philippe: For a good (or perhaps bad, in this case) laugh, visit http://www.teachercreatedmaterials.com; they’ve managed to continue hacking on the original Netscape script in a ridiculous manner.
Dorus: That’s not a bad idea, and it sounds like a good job for Mozilla Corp’s Evangelism team. I actually think it’s worth noting in bug 334967, or at the very least filing a separate bug for it.
02.22.09 at 3:02 pm
We need to google bomb the gecko is gecko page
02.22.09 at 6:12 pm
Nothing to add except that you’re my hero. Seriously.
02.22.09 at 11:52 pm
Silly Boy.
People cut and paste the code they have.
To complain about code with out providing a variety of correct cut and paste examples is just a waste of time and web space.
— Thank You —
Mr. Steven G. Liggett
SGLiggett@msn.com
02.23.09 at 1:55 am
Mr. Steven G. Liggett: I’m free to complain about whatever I want, and it’s not a waste of my time or my webspace at all when I do so.
But you’ve missed the problem: web developers shouldn’t be doing browser sniffing at all, so they don’t need “correct” examples of browser sniffing to copy. Instead, they should be using methods like Test-Driven Progressive Enhancement or object detection to make sure their sites work properly with whatever capabilities their users’ browsers present.
By the way, these sites have sample code for developers to copy-and-paste, and they are all linked from the article that the third tip urged everyone to read.
02.23.09 at 2:56 am
Smokey,
. I regularly see people on web development mailing lists with questions like ‘problem with netscape’.
That teachercreatedmaterials site is a sad thing. And unfortunately, there are more of those
On a related note, did you know that OmniWeb is denied access to FruitCo’s me.com ?
02.23.09 at 2:32 pm
I just set up a redirect for that old sniffer page on http://www.mozilla.org to point to
https://developer.mozilla.org/En/Browser_Detection_and_Cross_Browser_Support
If there are any other old sniffer docs on http://www.mozilla.org that you know about, send me the links and I can redirect those too.
BTW, I’d like to help bring back the Gecko is Gecko content. If there’s any interest in doing that, feel free to let me know.
02.24.09 at 2:46 am
David: Thanks for the redirect. There’s one other outdated sniffer I’ve stumbled upon somewhere on mozilla.org; I’ve filed a bug about getting it removed (or commented in an existing bug about it; I forget), but I’ll have to go look it up when I’m a bit less harried.
What I dislike about the “Browser Detection and Cross Browser Support” article—and the reason I didn’t link to it directly in my post—(and I’ve said this other places before, including in some relevant bug) is that it’s very much a product of its time. It was a great document for 2003, but now we need something better, stronger, and more in tune with the problems of 2009. The current document is very verbose, and it spends a lot of time telling you not to do the “Ultimate JavaScript Client Sniffer” stuff (which is still needed, alas), but very little time telling you 1) you don’t need to “sniff” browsers at all, 2) you should use object detection (with several examples, and some complete examples, too), and 3) if object detection won’t work and there are quirks or bugs you need to address, apply workarounds to rendering engines, not browsers.
That’s the motivation behind my “Gecko is Gecko” article on wikimo and the source of the article’s structure. Unfortunately, I have too many irons in too many fires, and I don’t really have the technical expertise to fill in all the details/sample code.
If you’d like to put some effort behind it, I’d be very happy to see that happen!
(I’ll shoot you an email soon.)
Also, for everyone following along at home, Dorus filed the bug mentioned in comment 2 as Bug 479835; thanks, Dorus!
02.24.09 at 8:13 pm
[I am reposting this for the 3rd time on your blog. Obviously, it is not possible to reply in your blog without first removing all the links. An unannounced policy and a very counter-productive one.]
Mr Ardisson,
What you did not write is URLs to recommended and recommendable practices
for writing cross-browser webpages. Here’s a few:
1-
Developing Cross Browser/Cross Platform Pages: Using Object/Feature
support detection approach: best and overall most reliable
http://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Developing_Cross_Browser%2f%2fCross_Platform_Pages#Using_Object.2fFeature_support_detection_approach.3a_best_and_overall_most_reliable
2-
A Strategy That Works: Object/Feature Detecting from comp.lang.javascript
newsgroup FAQ notes
http://jibbering.com/faq/faq_notes/not_browser_detect.html#bdFD
3-
Browser detection – No; Object detection – Yes by Peter-Paul Koch
http://quirksmode.org/js/support.html
4-
Javascript Best Practices: Feature-Detect Rather Than Browser-Detect by Matt Kruse
http://javascripttoolbox.com/bestpractices/#detect
5-
Browser detection by Garrett Smith
http://dhtmlkitchen.com/?category=/Browsers/&date=2007/11/24/&entry=Browser-Detection
People should not be explained how or why the previous methods were wrong, inappropriate, difficult to manage, unreliable not as much as being explained what to do, what is best to do, most recommendable, how to write good and reliable cross-browser code with examples, preferably real examples coming from real websites, preferably with interactive examples
which they can try, examine and use (and even eventually copy+paste).
regards, Gérard Talbot
02.25.09 at 5:49 am
I surf with Javascript disabled by default. Surprise surprise, teachercreatedmaterials.com appears to work fine without any kind of scripting. Then again, I only did the most superficial of checks. Where’s their browser detection script anyway?
02.25.09 at 7:30 pm
Gérard Talbot: There’s no policy, unannounced or otherwise, to prevent comments with links (see for example the post from David Boswell). However, Akismet decided that your prior posts were unequivocally spam rather than flagging them for my review as questionable.
As I’ve noted earlier, I did post a link to page that explained the proper methods for constructing cross-browser web pages, although it doesn’t itself have lots of copy-and-paste examples. I specifically did not link to the existing Mozilla Developer Center article because of the problems with it that you and I have both identified.
02.25.09 at 9:42 pm
Felix Pleșoianu: The sniffer is in http://www.teachercreatedmaterials.com/include/js/menu.js; I’m not sure that the JavaScript is actually doing anything, either (besides showing the annoying “your browser is not one of these five” alert on every pageload
).
02.26.09 at 1:21 pm
Smokey, thanks for clarifying why you hadn’t linked to that page in your post. I guess I missed that point when I redirected the page
I’m happy to re-redirect that to wherever makes the most sense, but I’m not really in a position to judge where the best documentation is. My web developer skills are firmly frozen in the late 1990s. I’m also happy to help clean up any old http://www.mozilla.org issues. I’ll take a look and see if I can find the bugs you mentioned above.
02.26.09 at 3:10 pm
(at) David Boswell,
This is word for word, byte for byte what I emailed you (and 2 other mozilla.org people) on August 3rd 2008:
”
The Ultimate JavaScript Client Sniffer, Version 3.03:
Determining Browser Vendor, Version, and Operating System With JavaScript http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html should be deleted, removed, terminated and not necessarly archived. My opinion, my preference.
”
Regards, Gérard
02.26.09 at 3:59 pm
David: For the moment, that’s still the best page to redirect anyone looking for the sniffer to; it’s just not the optimal solution in the long term.
The other sniffer I mentioned earlier is bug 471835; I was hoping dbaron or someone else who could be deemed “responsible” for those pages would have commented. Note that page also exists on the Mozilla Japan website; is someone there tracking the archiving work that you, Sam Sidler, and others are doing on mozilla.org?
Gérard Talbot: The Ultimate JavaScript Client Sniffer pages were archived in August 2008; David just changed the 404-with-clickthrough-to-archive to a redirect to MDC’s slightly better (more correct) documentation.
02.27.09 at 12:06 am
Smokey, good point about coordinating with Mozilla Japan about archived content. I’ll look into that.
05.26.09 at 3:35 pm
Not that I care what you guys think about my site, but I have removed the sniffer just because it was not really doing much. It is good that you guys are bringing this up though. Keep up the good work.
05.26.09 at 3:58 pm
Al Murillo: It’s good to hear that the sniffer is gone from your site. Hopefully one day that old Netscape script will be only a distant memory for the entire web! There are still lots of “broken” sites out there, but every fix helps, so thanks again for removing the sniffer from yours.
We’re still working on getting better and updated Mozilla documentation for authors, too, but there has been some progress since this originally came up in February.