web blazonry web development scripts and tutorials Get best price on Prepaid Cheapest Smartphone
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   

Javascript Home

image scripts
  Image Load Order
  Mouse Overs

JavaScript Resources
  Free JavaScript Books(new)
  Recommended Sites
  Bestselling Books

Bookmark and Share

JavaScript : Browser Versioning

There are different browsers and versions out there. Thus you, the programmer, do not know what JavaScript capabilities the user has. Insuring that the scripts you write run in most users browsers can be done in a few different ways.

One way is to use JavaScript to check which browser they are using, and then program accordingly. This is the most common way to avoid any scripting errors on the different browsers.

The information at the top of the page was printed out using the following functions, which retrieve the browser version, name and user agent:


The (Netscape) Navigator name is part of the function because Netscape created JavaScript. Here are some examples have how these can be used:

<SCRIPT LANGUAGE="JavaScript"><!--

var iVer = parseInt(navigator.appVersion);
var sName = navigator.appName;

if (iVer >= 3) { ...perform some function... }

if (sName == "Netscape") { ... do this ... }

else if (sName == "Microsoft Internet Explorer")
{ ...do something else... }


You can also use this when calling functions within the body part of the document. For example:

<INPUT TYPE=button
onClick="if (iVer >= 4) doThisFunction();">

However, the above way requires you to know which specific functions and methods are supported by which browser, and which version. The following two ways try to get around that.

A way to try to version-detect your scripts is to use the actual script tag. You can specify the version in the LANGUAGE value. The browsers which support the level of JavaScript specified will run the script, if not supported it should not run it. This feature is only supported by Netscape. Examples:

<SCRIPT LANGUAGE="JavaScript1.0"> <SCRIPT LANGUAGE="JavaScript1.1"> <SCRIPT LANGUAGE="JavaScript1.2">

Netscape ver 2.02 supports JS ver 1.0, Netscape 3.0x supports ver 1.1, and you could probably guess that Netscape 4.0x supports JavaScript ver 1.2.

However, that way requires you to know which functions came out in what version, and it only works on Netscape, which is not good enough.

Another way to try to assure your scripts run fine, is not to check what browser is used, but to check if the JavaScript object is defined. You can do this with a simple if statement.

For example, in 2.0 browsers, images are not defined as objects in JavaScript, thus the JavaScript object document.images is not defined. Undefined is considered to be false, such as in an if statement.

if (document.images) { ...document.images is defined }

That is all there is to it. The drawback to using this method is that you may have several if statements checking several different objects at once.

It is always best to check your code in numerous different browsers, with numerous different settings.


Related Links:



Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.