Sidebar


Browser Compatibility Issue

The source code for this article is written in JScript for Internet Explorer 5.0. While everything the components do can be accomplished in Netscape JavaScript, I thought it was more important to show a clear example of implementation, rather than getting bogged down in compatibility issues. I chose IE JScript for the examples because it allows a cleaner implementation of the "simplified" component framework described in the article. For example, the latest version of JScript lets you extend the attributes of standard HTML objects by adding key/value pairs to the tag. Listing One shows how these extended attributes determine the class of the component and constructor parameters. Since Netscape JavaScript recognizes only standard attributes, you could embed the information in one of those properties (such as NAME), or just create an associated hidden input element containing the data.

The init function of wCLASSinit uses JScript's all.tags() method to efficiently gather form elements of a certain type, narrowing the search for the component elements. The "all" collection is available only in JScript; and while convenient, is not necessary. The last compatibility issue is the keystroke event handling in FormatText, which is significantly different in the two browsers. JavaScript will pass the event object to the onkeydown event, while JScript leaves it as an attribute of the window. JScript and JavaScript even store the key code in different properties of the event object. Coding JavaScript/JScript has always been an art of compromise. Hopefully, the European Computer Manufacturers Association (ECMA) and W3C will be stabilizing factors as Web-client scripting embraces XML and the new Document Object Model. --SJ