Categories:
Partners
Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

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">
alert("hi!")
</script>

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>

<script language="javascript1.1">
js_version=1.1
</script>

<script language="javascript1.2">
js_version=1.2
</script>

<script language="javascript1.3">
js_version=1.3
</script>

<script language="javascript1.4">
js_version=1.4
</script>

<script language="javascript1.5">
js_version=1.5
</script>

<script language="javascript2.0">
js_version=2.0
</script>


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

Output:

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.

Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.