A picture of me taking it easy

I'm currently on parental leave till September. During that time, I will not read any e-mail or blog comments.

Until I'm back, please read through my archives, take a look at my code/applications and check out my pictures.

Have a great summer, and a splendid winter to you aussies and kiwis! :-)

Object detection

Published on Tuesday, May 10th, 2005

I’ve been meaning to write this post for a long time. But, as always when you hesitate, someone else comes along and writes exactly what you were going to write (in this case, Mark Wubben beat me to it). But I’m just going to write it anyway!

First, what is object detection? The general purpose of it is to check in JavaScript if, for instance, a certain method is supported as opposed to relying on detecting what web browser the visitor uses. For example:

// Object detection
if(document.getElementById){
	// Use the document.getElementById method
	// to access an element
}

// Browser detection
if(navigator.userAgent.search(/MSIE/) != -1){
// Deliver IE-specific code
}

Generally speaking, it is good practice to use object detection, especially given all different web browsers that there are out there in the market. It is also a way of, as good as it can be done, future-proofing your application.
But it’s not the perfect solution that will work in all scenarios. I totally agree with Mark when he says that one has to compliment it with some browser detection, because there are web browsers out there that claim to support one or the other method, hence passing the object detection and then miserably failing on what one is trying to do.

I think it’s a bit narrow-minded to say things like:

Javascript will never use browser detect…

and

…you should never EVER use a browser detect

Sure, in a perfect world. But the world isn’t perfect, we still have to deal with web browsers that will act like they support what you’re trying to accomplish, but that then won’t support it a 100% or stable enough. Web interface development comes down to experience in web browser behavior, so it’s a bit pig-headed to say to never use something that in some cases will be a necessary complement. Web developers should use object detection as far as they can, but be ready to swallow their pride and use some browser detection to cover up for web browser flaws if necessary.

I mean, what counts in the end is the result, isn’t it?

Posted in Developing | 5 comments

5 comments

Share your thoughts:

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> . If you want to display code examples, please remember to write &lt; for < and &gt; for >.

Comment preview

All the proceeds from ad clicks will go to charity. However, if you like to give something directly to charity yourself, I recommend choosing from the listed ones below.

  • Save the Children
  • Red Cross
  • Cancer Research UK
  • WWF

Top results