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 Value | Description |
Nothing, attribute omitted | Basic JavaScript functionality. |
JavaScript | Basic JavaScript functionality. |
JavaScript1.1 | Version 1.1 language capabilities. |
JavaScript1.2 | Version 1.2 language capabilities. |
JavaScript1.3 | Version 1.3 language capabilities. |
JavaScript1.4 | Version 1.4 language capabilities. |
JavaScript1.5 | Version 1.5 language capabilities. |
VBScript | Visual BASIC scripting in MSIE browsers. |
Tcl | In 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.
If a browser does not support the specified language, it may not execute the script block, even with a degraded version of the interpreter.
Be aware that Netscape 4 supports some special capabilities in JavaScript version 1.2 mode that are not strictly correct according to the ECMA standard nor are they compatible with earlier versions of Netscape Navigator and other browsers. If you find that you need to turn on JavaScript version 1.2 with the LANGUAGE attribute, check your scripts for portability very carefully.
<!-- 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 |
Prev | Home | Next |
<SCRIPT ID="..."> | Up | <SCRIPT> |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |