<SCRIPT LANGUAGE="..."> (HTML Tag Attribute)

The required version of JavaScript to interpret the enclosed code.

HTML syntax:<SCRIPT LANGUAGE="..."> someCode </SCRIPT>
Argument list:...The script language to use for this block of script source
someCodeSome script source text

As you embed the script code into an HTML page with the <SCRIPT> tag, you can indicate by means of the LANGUAGE attribute which version of JavaScript (or indeed other scripting languages) the interpreter should use to process the script. This is subtle and allows various aspects of the language to be switched so that they behave differently according to the version selection.

It also provides a way to hide JavaScript written according to newer syntax conventions from older browsers that cannot cope with it. In general, you should always try to specify the lowest version of JavaScript to achieve maximum portability.

JavaScript version 1.2 implemented some different capabilities regarding equality tests where the operands were different types. Selecting LANGUAGE="JavaScript" as opposed to LANGUAGE="JavaScript1.2" affects how these tests are carried out when the script is executed.

The following values are legal for the <SCRIPT> tag's LANGUAGE attribute:

Attribute ValueDescription
Nothing, attribute omittedBasic JavaScript functionality.
JavaScriptBasic JavaScript functionality.
JavaScript1.1Version 1.1 language capabilities.
JavaScript1.2Version 1.2 language capabilities.
JavaScript1.3Version 1.3 language capabilities.
JavaScript1.4Version 1.4 language capabilities.
JavaScript1.5Version 1.5 language capabilities.
VBScriptVisual BASIC scripting in MSIE browsers.
TclIn the HTML 4.0 specification, Tcl is used as an example.

The example below will display the text 1.3 in a Netscape 4.7 browser and the value 1.4 in version 5 of MSIE for Macintosh.

Note with this technique that you should ensure you test for a high enough version. The browsers will execute the versions indicated. If you only test up to version 1.2, then the variable assignment is never going to reflect a 1.4 version capability.

Warnings:

Example code:

   <!-- JavaScript version detector --->

   <HTML>

   <HEAD>

   <SCRIPT LANGUAGE="JavaScript">    myVersion = "Generic";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.0"> myVersion = "1.0";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.1"> myVersion = "1.1";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.2"> myVersion = "1.2";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.3"> myVersion = "1.3";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.4"> myVersion = "1.4";</SCRIPT>

   <SCRIPT LANGUAGE="JavaScript1.5"> myVersion = "1.5";</SCRIPT>

   </HEAD>

   <BODY>

   <SCRIPT>

   document.write(myVersion);

   </SCRIPT>

   </BODY>

   </HTML>

See also:<META>, <SCRIPT TYPE="...">, <SCRIPT>, Compatibility, Element.language

Cross-references:

Wrox Instant JavaScript - page 42