Feature Detection



JSWe recently looked at detecting browser information, such as browser name, number, and operating system. You might be tempted to use this information to decide on whether to use features that not universal across browsers. But this might be the best thing to do-you're much better off doing feature detection.



Feature detection is a method for testing the existence of a specific feature. If you use browser detection routines, you not only have to include a check for all browser names and versions that support your feature, but you might have to update this code every time a new browser is released.
But by using feature detection, it doesn't matter when new browsers are released-your code will still work. Let's do an example.
if (document.all)
{
// Use document.all
}

document.all was an Internet Explorer only property many years ago. In the above, we check to see if the property exists on the document object. The expression is true if the property exists, and false if it doesn't.


No comments :