Skip to content
Chicago Tribune
PUBLISHED: | UPDATED:
Getting your Trinity Audio player ready...

Dear Final Debug: I’m an Intranet developer and I’m finding out that much of what I need to do can be deployed in JavaScript. But there seems to be so many different versions of it, I don’t know how to write standard scripts. Any ideas?-Terry Bronard, Milwaukee.

Final Debug responds: Terry has been waiting for an answer from Final Debug readers through the contest for a few weeks now, so we’ll help out.

Last we counted, there were five different implementations of the JavaScript language: Netscape has different commands in its version 2, 3, and 4 browsers, while Microsoft implemented the nonstandard JScript in Internet Explorer 3 and a closer-to-Netscape’s-version JavaScript in IE 4. You could write a book listing the many differences and workarounds-someone may be working on one right now-but for our purposes we’ll focus on the new elements in standard JavaScript for Navigator 4 and some notes on compatibility with earlier versions. Our major source for information is the Netscape DevEdge program, which maintains a site full of technical documentation forJavaScript.

There may be a happy ending, though. The European standards group ECMA has approved JavaScript as an official language, and Netscape, Microsoft, and Sun all promise that future implementations of their browsers and tools will conform to the standard. That doesn’t help you much today, though.

What’s New

Here’s an overview of the most important differences or improvements in the latest JavaScript.

Events There’s now an event object and event capturing. The event object contains properties that describe a JavaScript event and is passed as an argument to an event handler when an event occurs. Event capturing lets a page capture an event before the target object gets it.

Functions You can now nest functions within functions. You can also convert objects to numbers or strings.

Layers These are available only in Navigator 4.0. The JavaScript angle is that each layer in HTML has a corresponding layer object that allows you to use JavaScript to manipulate the layer.

getSelection This new document method returns a string containing the text of the current selection.

preference This new navigator method lets a JavaScript manipulate browser preferences, like whether Java should run.

substring A major string method change that no longer swaps index numbers when the first index is greater than the second.

Objects They can now be created using literal notation.

Managing JAR files Two new navigator methods, language and platform, let you direct different JAR files to different setups.

Signed scripts You can now give your JavaScripts access to some normally restricted information.

Keeping Compatible

Let’s quote Netscape’s developer instructions directly on this:

Statements within a (less than)SCRIPT(greater than) tag are ignored if the browser does not have the level of JavaScript support specified in the LANGUAGE attribute; for example:

Navigator 2.0 executes code within the (less than)SCRIPT LANGUAGE=”JavaScript”(greater than) tag; it ignores code within the (less than)SCRIPT LANGUAGE=”JavaScript1.1″(greater than) and (less than)SCRIPT LANGUAGE=”JavaScript1.2″(greater than) tags. Navigator 3.0 executes code within the (less than)SCRIPT LANGUAGE=”JavaScript”(greater than) and (less than)SCRIPT LANGUAGE=”JavaScript1.1″(greater than) tags; it ignores code within the (less than)SCRIPT LANGUAGE=”JavaScript1.2″(greater than) tag. Navigator 4.0 executes code within the (less than)SCRIPT LANGUAGE=”JavaScript”(greater than), (less than)SCRIPT LANGUAGE=”JavaScript1.1″(greater than), and (less than)SCRIPT LANGUAGE=”JavaScript1.2″(greater than) tags.

By using the LANGUAGE attribute, you can write general JavaScript that Navigator version 2.0 and higher recognize and include additional or refined behavior for newer versions of Navigator.

Hope this helps, Terry. Next week we’ll have a new contest. Our next question will be about C++. Don’t say we didn’t warn you.