Javascript fallback and the noscript tag
Posted Dec 3rd, 2008 by David Calhoun in accessibility, javascriptAs you may or may not know, there are users across the internet who don’t have Javascript. Yes, that might be shocking and terrifying, but you have to deal with it!
Good websites try to code in such a way that allows all users to access content, with or without Javascript or other plugins. This is what’s coded first. Then all the cool Javascript interaction and such is added on top later, for Javascript-enabled users (the majority). This is called Progressive Enhancement, a buzz word you should know about if you’re in the web development business. I’m sorry to say that I myself didn’t know anything about this until recently, when I immersed myself into more modern web development. Oh yeah, and when I was asked about it on my internship interview with Yahoo. How embarassing that I had to confess I hadn’t even heard the term…
Anyhow, long story short, the <noscript> tag comes in handy. Code rendered inside this tag will only render when the user doesn’t have Javascript enabled. So at the very least you do something like this:
<noscript>Sorry, this site requires Javascript. (and I was too lazy to make the site work without it)</noscript>
I’m sure someone will find this useful, even though it might seem obvious to the veteran developers. Someone who might benefit might be this site I came across today (to be fair, it looks like it was developed a while back, since the layout uses tables).
I was a bit confused at first because I saw the common “This page requires that JavaScript is enabled on your browser” message. I thought something was wrong with my computer, since obviously I have Javascript enabled. But then I realized the text is hard-coded and displays for all users.
All the developer had to do was put that text in <nocode> tags! But instead it results in some confused visitors.
Leave a Reply
Categories
- accessibility (1)
- browser bugs (2)
- css (6)
- html (6)
- javascript (9)
- jquery (3)
- mobile (1)
- performance (2)
- php (1)
- regular expressions (1)
- rss (3)
- seo (1)
- Site News (1)
- table (1)
- Uncategorized (4)
- videos (2)
- wordpress (1)
- xml (2)
- yui (0)
I tend not to use the ‘noscript’ tag, it only works if JavaScript has been disabled from within the browser. If, however, the user is behind a strict corporate firewall/proxy (which strips out all the JavaScript before it get’s to the client machine) then the ‘noscript’ tag proves ineffective.
A good alternative is to have the non-JavaScript text display as default within the page and then hide it with JavaScript.