Five Most Common Coding Errors
The third worst mistake that Javascript beginners make is to use Browser Detection to determine what Javascript code to run on which browser. The problem with doing this is that there are hundreds of different browsers that you would really need to test for in order to get the code exactly right with new versions being introduced just about every day (have you updated your browser detection script to recognise today's new browser versions?)
When people do use such a script they usually just test for the two or three most commonly used browsers and totally stuff up the web page for anyone using a less common browser. Even with the browsers that they do cater for a lot of work is required to recode the script every time a new version of one of those browsers comes out with different functionality.
A much better solution to using browser detection is to use Feature Sensing to test if the browser supports the particular code that you want to use.
About the only exception I can think of where it makes sense to use browser sensing instead of feature sensing is if you have a script that is written in JScript instead of Javascript. Since JScript only runs on Internet Explorer it would make sense to have the entire script automatically commented out if you have Identified Internet Explorer is not the browser being used. The reverse situation doesn't really apply since valid Javascript code is almost always valid JScript code as well.
When people do use such a script they usually just test for the two or three most commonly used browsers and totally stuff up the web page for anyone using a less common browser. Even with the browsers that they do cater for a lot of work is required to recode the script every time a new version of one of those browsers comes out with different functionality.
A much better solution to using browser detection is to use Feature Sensing to test if the browser supports the particular code that you want to use.
About the only exception I can think of where it makes sense to use browser sensing instead of feature sensing is if you have a script that is written in JScript instead of Javascript. Since JScript only runs on Internet Explorer it would make sense to have the entire script automatically commented out if you have Identified Internet Explorer is not the browser being used. The reverse situation doesn't really apply since valid Javascript code is almost always valid JScript code as well.