January 27, 2000 - Hiding New Features

Yehuda Shiran January 27, 2000
Hiding New Features
Tips: January 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

When a new JavaScript version is released, new features are introduced with it. When using these features, you have to hide them from older versions of JavaScript. The cumbersome way is to remember which browser versions were released with the new JavaScript version, and to hide the new features from older versions of these browsers. It is much simpler just to specify the new JavaScript version in the <SCRIPT> tag. Only JavaScript engines matching this version will interpret the code. Older versions of JavaScript engines will just ignore this tag, and will not interpret the JavaScript section. The following JavaScript code will be processed only by JavaScript engines of 1.3 and up:

<SCRIPT LANGUAGE="JavaScript1.3">
<!--
 function handleClick() {
   alert("This browser supports JavaScript 1.3 and up");
}
document.write('<FORM NAME="jukebox">Hit the button:<INPUT TYPE="button" ID="display" VALUE="Demo 1.3" onclick="handleClick()">');
// -->
</SCRIPT>

You should see a Demo button here:

If you don't see the button, your browser does not support JavaScript 1.3. The following code will be exercised only when JavaScript 1.4 comes along:

<SCRIPT LANGUAGE="JavaScript1.4">
<!--
 function handleClick() {
   alert("This browser supports JavaScript 1.4 and up");
}
document.write('<FORM NAME="jukebox">Hit the button:<INPUT TYPE="button" ID="display" VALUE="Demo 1.4" onclick="handleClick()">');
// -->
</SCRIPT>

You should see a Demo button here when JavaScript 1.4 is out:

Many features have been introduced in JavaScript 1.3. Learn more about them in Column 25, JavaScript 1.3 Overview, Part I, and Column 26, JavaScript 1.3 Overview, Part II.