Click on a button to choose a background colour and click the Font+ or Font- buttons to make the text larger or smaller

Caroline's Corner

Home

Web Development


Some JS Basics

Versions of JS

Data

If Statements

Loops

Functions


Check Pc & Browser Specs

Calculator

Count Calories

Search

Compare Colours

Scrolling Background

FAQ

Links to JS Tips, Tutorials & Tools

What Version of Javascript?

Javascript like all programming languages (and all programs for that matter) has evolved over time. What this means is that new commands have been added to the language to support additional functionality and make it easier to use Javascript to provide various tasks. At the time of writing the latest release browsers support Javascript 1.5.

Commands introduced in newer versions of the language are only supported when the browser that your visitor is using supports the same or a later version of Javascript than the one in which the command was introduced. If your visitor is using a browser that only supports an earlier version of Javascript then commands that are not recognised in that version will cause unexpected results, may cause the script to crash, or may even cause the browser itself to crash (although this last is unlikely). To resolve this you can either avoid the use of commands only supported by more recent versions of Javascript or test the browser first to see what version is supported.

So how can we determine which version of Javascript a given browser supports? Well Javascript doesn't contain anything that can test for which version is supported but surprisingly HTML does. By combining HTML and javascript together we can set up a Javascript variable containing the version number as follows:

<script type="text/javascript">
var jsver = 1.0;
</script>
<script language="Javascript1.1">
jsver = 1.1;
</script>
<script language="Javascript1.2">
jsver = 1.2;
</script>
<script language="Javascript1.3">
jsver = 1.3;
</script>
<script language="Javascript1.4">
jsver = 1.4;
</script>
<script language="Javascript1.5">
jsver = 1.5;
</script>
<script type="text/javascript">
document.write('<p><b>Javascript version ' + jsver
+ ' supported<\/b><\/p>');
</script>

The following paragraph is produced by the above code to tell you what version of Javascript your browser supports.

Javascript version 1.3 supported

If the above message doesn't say that your browser supports version 1.5 then you might consider upgrading your browser to one that does. The following lists which version of Javascript the more recent versions of the more common browsers support.

Firefox, Netscape 6/7, Mozilla, and Opera 7 all support version 1.5
Opera 6 supports version 1.4
Netscape 4.5, Opera 5, and Internet Explorer 6 support version 1.3
Netscape 4 supports version 1.2

There will be times that you want to design a script that includes the functionality that is not available in some older JavaScript enabled browsers, such as Internet Explorer 3 or Netscape 3. You need to know how to accommodate the older browsers with your script. Knowing what versions of JavaScript are supported by what browsers and how to detect the versions in your scripts allows this.

Even though Netscape 3 and Internet Explorer claimed to both support version 1.1 of JavaScript, there was a considerable difference between the two. The difference between the versions in Netscape 4 and Internet Explorer 4 is much less making it much easier on us when we design our pages. I am talking about what I call conventional JavaScript. Cascading Style sheets and Dynamic HTML are still different in the two browsers.

Internet Explorer refers to it's version of JavaScript as JScript. JScript comes in versions 1.0, 2.0, and 3.0. JScript recognizes the "JavaScript" as a language property of the SCRIPT tag and is compatible with JavaScript as defined in the paragraph above.

The language property of the SCRIPT tag can be used to isolate scripts for specific versions of JavaScript by including the version. Here is the method you should use to allow for multiple versions of JavaScript.

<script Language="JavaScript">
statements for all Versions
</script>
<script Language="JavaScript1.1">
statements for Versions 1.1 and later
</script>
<script Language="JavaScript1.2">
statements for Versions 1.2 and later
</script>
<script Language="JavaScript1.3">
statements for Version 1.3
</script>
<script Language="JavaScript1.4">
statements for Version 1.4
</script>
<script Language="JavaScript1.5">
statements for Version 1.5
</script>

Notice that the above snippet of code contains 6<script> tags. Also note that the language property is different for each. This is how you isolate scripts for specific versions of JavaScript. Most of the time you will only use the first one. However, if you want to use some code that only works for a specific version, then you must include the <script> tags for that one too.

For example, suppose you write a great function that only works in JavaScript version 1.4. Then, you must place it between the <script> tags for version 1.4. You must also include the top tag to accommodate older browsers with a different version of your function in it. Here is what it would look like.

<script Language="JavaScript">
function myGreatFunction(){
my statements for versions prior to Version 1.4
}
</script>
<script Language="JavaScript1.4">
function myGreatFunction(){
my statements for Version 1.4
}
</script>

The bottom myGreatFunction() would be executed on browsers that support JavaScript version 1.4 or later whereas the top myGreatFunction() would be executed on browsers that supported JavaScript version 1.0, 1.1, 1.2 or 1.3. Notice that the newer version scripts are placed last. Also notice that you only have to include <script> tags for the versions that are directly affected. There will be times that the function that you place in the upper <script> tag will just be a dummy function that does nothing but it must be there to prevent JavaScript errors.

Learn more here - http://www.javascriptmall.com/learn/contents.htm

The Links to JS Tips, Tutorials & Tools page contains links to all the sites I have taken scripts and information from for this site. In places I have blended scripts from several sources. I would like to thank all the people who provide and support these sites for the wonderful resource they provide to students of the Web.