Accessible JavaScript = Unobtrusive JavaScript
"As described in the Web Accessibility Guide the key to Accessible JavaScript is Unobtrusive JavaScript."
JavaScript is not my favorite topic –- I think it’s over used and used badly by people who should know better. There are so many ways badly implemented JavaScript can cause problems for both users and search engines alike that I often feel that it’s better to not use it at all.
However, the reality of it is people like using JavaScript and there are actually some good uses for it. As I describe in the Web Accessibility Guide the key to Accessible JavaScript is Unobtrusive JavaScript. Unobtrusive JavaScript essentially means making sure the site will work without JavaScript enabled. All critical functions of the site must be usable without JavaScript – this includes navigation and form submission among other items.
Additionally, it’s important to learn how to create your own scripts and not depend on pre-made scripts available on any old web site. Most of the scripts available on those sites use out of date methods that can cause more harm than good. If you do need a pre-made script, find a recently created one from a reputable source and make sure you understand how it works. Also make sure the script has to two essential features:
- All functions and event handlers must be in a separate .js file – separating behavior from structure is the key to unobtrusive JavaScript.
- All functions that use onMouseOver onMouseOut handlers must also use onFocus and onBlur handlers so that the script will work for keyboard users.
Before creating a site it’s important to think deeply about what will be needed to do whatever it is that needs to be done. If JavaScript is absolutely necessary make sure it’s unobtrusive and as usable as it can be. Take the time and effort to use JavaScript correctly and test it thoroughly before letting the site go live. If there are problems fix them – don’t leave them and hope people won’t notice, because they will. There’s no point in having a site if people can’t use it and search engines can’t index it properly.