JavaScripting Netscape 6: No More Sloppy Code | 6 | WebReference

JavaScripting Netscape 6: No More Sloppy Code | 6

123456
[previous]

Summary

Scripting for NS6 and IE5.5 takes special care to adhere to standards and good programming practices. Each browser acts differently for external scripts, and you must be careful to encapsulate your element-dependent executable within functions called onload. Netscape 6 is particularly sensitive to improperly nested HTML when executing dynamically loaded scripts. By following these best coding practices, and coding for the DOM, you can ensure your scripts will work for current and future generations of browsers.

Steps for supporting NS6 with your HTML+CSS+JavaScript

  1. Properly Nest all HTML Tags
  2. Properly Close all HTML Tags
  3. Validate your HTML
  4. Validate your CSS
  5. Choose the appropriate DOCTYPE, if any
  6. Encapsulate element-dependent JavaScript within onload functions
  7. Define onload handers within external files, or subsequent SCRIPT blocks

We've provided some test cases to illustrate the problems that we discussed, and also some workarounds.

Further Reading

# # #

About the author: Andrew B. King is the founder and Managing Editor of WebReference.com. He holds a BSME and MSME from the University of Michigan. He's been creating Web sites since 1993 and still can't find time for his own home page. He has written for Web Techniques, MacWEEK, and contributed to HTML and Web Publishing Secrets, by Jim Heid. Special thanks go to Dan Ragle of internet.com and Bob Clary of Netscape for their help in researching this article. Andy can be reached at aking@internet.com.

123456
[previous]

Created: February 15, 2001
Revised: Mar. 6, 2001

URL: http://webreference.com/programming/javascript/javascript/netscape6/