Important guidelines
First let's learn some important stuff. There are lots of browsers out there that cannot support JavaScript. Although browsers generally support more and more with each release, the language itself keeps evolving, and there is already a vast amount of the JavaScript language available for browsers to support. No browser will ever support all of it, and you cannot expect them to.
There are many reasons why people cannot or will not 'upgrade' to your chosen browser. A few are:
- They are at work and they can only use the system default browser.
- They want to view pages more quickly so they use a text only browser.
- They are blind or have poor eyesight so they need a text only browser/reader/Braille reader.
- They realise that the more extra features like JavaScript or VBScript you use, the more you leave yourself open to becoming a target for viruses or vulnerability exploits.
- They don't like the way some sites insist on taking over their control of the browser, opening popup windows, breaking the operation of the back button, preventing the context menu from working, or insisting on making things appear and disappear in a way that causes usability problems.
Whatever their reasons, you should not stop them from using your site. If your site
uses JavaScript for navigation or content, then that navigation and content should be there without JavaScript enabled.
Your JavaScript can extract content from the page, and do whatever it wants with that, but you
should make sure that content is available without the script. If you want to use a script in
way that you cannot simply extract the information from the static page, then you should use
<noscript>
to provide an alternative for people that cannot run your script.
There are also many browsers out there that you do not realise exist. I know of well over a hundred different browsers that support JavaScript to varying degrees. If your script uses something that browsers may not support, you should detect if the browser is capable of using it, and then fall back to an accessible alternative if it doesn't.
There is no magic formula for this, but the basic rules are that you should not detect a browser make or version. You will get it wrong, and you will mistakenly detect one browser and think it is another, ending up with you using the wrong code. You will make incorrect assumptions about current and future browsers, and you will cause problems for your users.
This tutorial should help you learn how to correctly detect capabilities, and wherever needed, it will show you how to work out when a browser cannot do what you need, so you can halt your script, or provide an alternative. When there are different ways to do the same thing, and some browsers only support one, while others support another, it will show you how to correctly work out which one to use.
Last modified: 4 September 2008