Variations of the language attribute

The variation of the language attribute occurs in the version number. You see, in the beginning of time, the only valid "language" value was "JavaScript." Then as JavaScript grew to support more features, the language attribute was used to indicate to the browser the version of JavaScript the containing script relies on, giving the browser the choice whether to execute the script or not depending on whether the browser supported these features. Here's an example of a language attribute declaration with version notes:

<script language="JavaScript1.5">

As of IE6, up to "JavaScript1.3" is supported, while in Firefox 1.x, "JavaScript1.5." So if you think about it, the above script will NOT be run in IE6, as IE6 will see such a language attribute as meaning it is incapable of running the containing script.

Here's an easy way to see up to what version of JavaScript your browser supposedly supports:

<script language="javascript">
var js_version =1.0

<script language="javascript1.1">

<script language="javascript1.2">

<script language="javascript1.3">

<script language="javascript1.4">

<script language="javascript1.5">

<script language="javascript2.0">

<script language="javascript">
document.write('<b>Your browser supports JavaScript ' + js_version + '</b>')


Now, as mentioned, the language attribute is optional, though it serve sas an easy way to write JavaScript version specific code in the rare cases demanding it. Browsers that do not support the JavaScript version indicated by the language attribute do not even load the script into memory for sake of efficiency.

Moving on, I'll demonstrate just how to use the language attribute to your advantage when writing scripts.

Follow Us
Facebook Fan Page