|
Free Open Book
Sams Teach Yourself JavaScript in 24 Hours |
Planning for the FutureIn the history of JavaScript, there has never been such a major change to the language that a great number of scripts written using the older version have stopped working. Nevertheless, many scripts have been crippled by new browser releaseschiefly those that used browser-specific features. The following sections offer some guidelines you can follow in writing scripts to ensure that the impact of future JavaScript versions and browser releases will be minimal. Keeping Scripts CompatibleYears ago, Netscape and Microsoft introduced separate and incompatible versions of DHTML (Dynamic HTML), which allowed scripts to modify any element of a page for the first time. Early adopters jumped in to write many scripts, some of which you can still find online today. These scripts made some serious mistakes:
This messy scripting gave DHTMLand JavaScripta bad name among serious programmers. Fortunately, the standardized W3C DOM has now replaced the proprietary browser DHTML features, and it's easier than ever to create scripts the right waybut as time goes by, there will undoubtedly be cutting-edge features that aren't quite standard. One obvious example is AJAX (Asynchronous JavaScript and XML), which is only now being developed as a standard by the W3C, despite working (in sometimes confusingly different ways) in the major browsers. There's nothing wrong with using these cutting-edge featuresbut if you do, you should be aware that you're going to need to test the scripts on several different browsers. You should use feature sensing rather than detecting (or expecting) particular browsers. Finally, you should be prepared to do a bit of rewriting when the standard arrives. Staying HTML CompliantOne trend as browsers advance is that newer browsers tend to do a better job of following the W3C standard for HTMLand, often, relying on it. This means that although a page that uses completely standard HTML will likely work in future browsers, one that uses browser-specific features or workarounds is bound to have problems eventually. By the Way In particular, the first release of Netscape 6.0 received many complaints about "breaking" previously working pages. In most cases, the page used bad HTML, and previous browsers happened to handle the error more gracefully. To avoid these problems, try to use completely valid HTML whenever possible. This means not only using standard tags and attributes, but following certain formatting rules: For example, always using both opening and closing <p> tags, and enclosing numbers for table widths and other parameters in quotation marks. To be sure your documents follow the HTML standard, see Appendix B, "Tools for JavaScript Developers," for suggested HTML validation programs and services. These will examine your document and point out any areas that do not comply with the HTML standard. Document EverythingLast but not least, be sure you understand everything your scripts are doing. Document your scripts using comments, and particularly document any statements that might look cryptic or are particularly hard to get working correctly. If your scripts are properly documented, it will be a much easier process if you have to modify them to be compatible with a future browser, JavaScript, or DOM version. Did you Know? See Hour 15 for more tips on future-proofing your scripts by using unobtrusive scripting techniques. |
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |