Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Reading Browser Information
- Supporting Browsers with JavaScript
- Supporting Non-JavaScript Browsers
- Workshop: Scripting for Multiple Browsers
- Summary
- Q&A
- Quiz
- Exercises
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
Supporting Non-JavaScript Browsers
What about browsers that don't support JavaScript at all? You can't detect them with a script because they won't even run the script. However, there are ways of dealing with these browsers.
With 99% of Web users using a recent copy of Netscape or IE, where are the non-JavaScript browsers? First, there are still some older browsers out there, and text browsers such as Lynx don't support scripting. Second, and more importantly, many Netscape and IE users have JavaScript support turned off, either due to security concerns or just to avoid watching scrolling messages in the status line.
In the last few years, a wide variety of new browsers have also emerged. Palmtop computers, such as 3Com's PalmPilot and the Windows CE platform, support Web browsing, as do some cellular phones and other appliances. Since none of these support JavaScript, it's even more important to provide an alternative when possible.
One way to be friendly to non-JavaScript browsers is to use the <noscript> tag. Supported in Netscape 3.0 and later, this tag displays a message to non-JavaScript browsers. Browsers that support JavaScript ignore the text between the <noscript> tags, while others display it. Here is a simple example:
<noscript> This page requires JavaScript. You can either download a copy of netscape from <a href="http://www.netscape.com/"> their page, or switch to the <a href="nojs.html">Non-JavaScript</a> version of this page. </noscript>
The main problem with using <noscript> is that Netscape 2.0 will display the text between the tags, even though it does support some JavaScript. While Netscape 2.0 isn't too common these days, there is a way to solve this problem. The following script detects non-JavaScript browsers and displays a message:
<script LANGUAGE="JavaScript" type="text/javascript">
<!-- //hide from old browsers
...script commands go here...
/* (start JavaScript comment, end HTML comment)
-->
You're using a non-JavaScript browser! Shame on you.
<!-- */ // -->
</script>
This uses the HTML comment tags (<!-- and -->) to hide the script commands from old browsers. It then uses JavaScript comment tags (/* and */) to enclose the message for non-JavaScript browsers, so it will be disregarded by browsers that support JavaScript.
An easier alternative is to send users with JavaScript support to another page. This can be accomplished with a single JavaScript statement:
<script LANGUAGE="JavaScript" type="text/javascript"> window.location="JavaScript.html"; </script>
This simply sends the user to a different page. If the browser doesn't support JavaScript, of course, the script won't be executed.
The final alternative is to simply make your scripts unobtrusive. Use comments to hide them from other browsers, as described in Hour 3, "How JavaScript Programs Work," and be sure they're not essential to navigate or read the page.
Workshop: Scripting for Multiple Browsers | Next Section

Account Sign In
View your cart