Part 8

Differences between Browsers

Browsers vary considerably in:

Therefore, creating web pages that will display correctly on all (or even most) browsers is not easy, particularly if the pages contain dynamic material.

However, use of a scripting language such as JavaScript allows us to create pages that will load and run correctly on a wide range of browsers.

 

Major differences between browsers include:

 

Browsers also differ in the support they provide for the JavaScript language. The level of compatibility offered by the various versions of Netscape and Internet Explorer (for JavaScript and Jscript respectively) is summarised below:

  Navigator version JavaScript version Comments
         
  2.0 1.0 First version of JavaScript.
Included some bugs/limitations, e.g.:
  * window.open() method doesn't work on Mac and Unix platforms.
  * Poor support for arrays.
  * onLoad() event triggered by re-sizing.
 
  3.0 1.1 Support for <src> attribute, allowing use of external JavaScript source code.
 
  4.0 - 4.05 1.2 Support for dynamic positioning of elements.
Signed scripts for security.
 
  4.06 - 4.5 1.3 ECMAScript 1.0 Compatible
 
  5.0 1.4 ECMAScript 2.0 Compatible
More advanced error-checking and control functions.

 

  Explorer version JScript version Comments
  3.0 1.0 Used a separate JScript Scripting Engine which could be upgraded separately from the browser. Many versions in use.
Particular problems when handling image attributes.
       
  4.0 - 4.5 3.0 ECMAScript 1.0 Compatible (and therefore largely identical to JavaScript 1.3).
Support for <src> attribute (but not until v3.02, and even then with bugs), allowing use of external JavaScript source code.
Support for dynamic positioning of elements.
 
  5.0 5.0 ECMAScript 2.0 Compatible (and therefore largely identical to JavaScript 1.4)

 

In addition to the differences listed above, there are many minor and not-so-minor differences in the way the various browsers suppport and interpret HTML and JavaScript. Most of these will be listed in any good HTML or JavaScript reference book.

 

Obtaining Browser Parameters

We can tackle differences between browsers using the Navigator object

This object returns properties related to the browser, such as its type, version, etc.. It also returns properties indicating the platform on which the browser is running (Macintosh, Windows PC, Linux PC, etc.),

 

Navigator object properties include:

  appName Returns a string representing the browser. For example, the code:
       
  alert(navigator.appName);
 
  should return a string containing the name of the browser you are using (e.g., "Microsoft Internet Explorer" or "Netscape")
 
  Click here to see this piece of code in operation.
 
  appCodeName Returns a string representing the code name of the browser. For example, the code:
 
  alert(navigator.appCodeName);
 
  should return a string containing the code name of the browser you are using (e.g., "Mozilla")
 
  Click here to see this piece of code in operation.
 
  appVersion Returns a string representing the browser version. For example, the code:
 
  alert(navigator.appVersion);
 
  should return a string indicating which version of the browser you are using (e.g., "4.0 (compatible: MSIE 5.0)")
 
  Click here to see this piece of code in operation.
 
  platform Returns a string representing the computer platform on which the browser is running. For example, the code:
 
  alert(navigator.platform);
 
  should return a string containing the name of the platform on which the browser is running (e.g., "Win32" or "MacPPC")
 
  Click here to see this piece of code in operation.

 

Using some or all of the Navigator object properties, It is possible to determine which browser is being used and then generate the appropriate code.

Click here to see a simple example.

This example includes a movable bar that has to be coded differently depending upon which browser it is being viewed under. The web-page tests to see what browser is being used, then generates appropriate code. The code used is quite simple and may not accommodate all browsers, but it should work under most widely-used browsers.

Have a look at the source code of the example to see how it works. Note the following points: