This information is being maintained for archive/historical purposes only.
It will not be updated.
Please see http://archive.cabinet-office.gov.uk for details.

 

Main navigation

In section navigation

4.6 Scripting and programming

Publishing date: May 2002

Web managers should be aware that scripting and programming could be used to add interactivity and style to their web pages. Three major forms of scripting and programming are now used within web browsers. JavaScript from Netscape/ECMA, Java from Sun Microsystems and ActiveX components from Microsoft.

Use each checklist to ensure that your web pages comply with these guidelines

4.6.1 Checklist and summary: Core guidance

Checklist

Summary

A variety of different scripting languages and programming can be incorporated into HTML pages. All are very powerful and can be put to good use.

It is important to ensure that your website remains usable in browsers that have scripting and/or Java/ActiveX turned off.

4.6.2 Introduction to scripts

A substitute for any information or action generated with client-side scripting or component or Java programming must be made available in standard HTML format for users with browsers that do not use these technologies.

Particular attention should be paid to the version number of the script being used. For example, browsers that only understand JavaScript 1 will not be able to interpret JavaScript 1.2. There are a number of ways around this problem. Historically, JavaScript routines typically first established the version of the user’s browser and then branched accordingly. Some parts of a script would, for example, be executed in Microsoft Internet Explorer and others in Netscape Navigator.

The rapid development of the browser document object models (DOMs) and of JavaScript language variants has the result that the traditional ‘browser sniffing’ approach is no longer considered adequate because it does not offer a fine enough degree of granularity. The recommended approach is to test for the existence of each specific DOM and scripting language object, property and method before attempting to use it.

The only way to fully test the compatibility of any script is to test the pages using a range of browsers (see section 2.5).

2.5 Browser compatibility

4.6.3 Problems with scripts

On the Internet, there are many occasions when scripts do not work as intended either because the scripting is incompatible with the user’s browser or as a consequence of the user’s inability through physical or motor impairment to use the functions presented by the script.

Any scripts used on the website must be thoroughly tested on a range of different browsers and operating systems to ensure full compatibility. Even then, there is a number of Web browsers that cannot render any script functions so no essential information should also be presented in standard HTML format.

In the process of testing the script, the author should always ensure that the page is not adversely affected if the scripting abilities of the browser are disabled.

Finally, the hosting service for the departments Website may possibly have policies regarding the use of scripting languages. It is advisable to check with your server administrator before implementing.

4.6.4 Scripting and programming technologies

4.6.4.1 Java

The Java programming language was introduced by Sun Microsystems in 1995 and instantly created a new sense of the interactive possibilities of the web. Both of the major web browsers include a Java virtual machine than can run Java ‘applets’.

Java is a programming language that uses an object-oriented programming model. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network. It can also be used to build a small application module or ‘applet’ for use as part of a web page. Applets make it possible for a web page user to interact with the page.

The major characteristics of Java are:

4.6.4.2 JavaScript (ECMAScript)

JavaScript is a scripting language developed originally by Netscape specifically for the web. In general, script languages are easier and faster to code in than precompiled languages such as Java. In the past script languages have generally take longer to process than compiled languages, but the just-in-time compilation techniques used in recent browsers mean this is no longer necessarily the case.

JavaScript is used in web pages to do such things as:

JavaScript uses some of the same ideas found in Java. JavaScript code can be embedded in HTML pages and is executed by the web browser. JavaScript can also be run at the server, as in Microsoft's Active Server Pages (ASP), before the page is sent to the requestor. ASP uses JScript that is a proprietary version of JavaScript.

Both Microsoft and Netscape browsers support JavaScript. The JavaScript language interacts with, but is distinct from the Document Object Model (DOM) in each browser. (See section 4.6.7.)

The widely encountered problem of web pages containing JavaScript that goes wrong arises from the large number of generations and dialects of the language that browser manufacturers have implemented many of which contain subtle and not-so-subtle incompatibilities. Such is the complexity of this issue that the commonly-used technique of testing the browser make and version number and making assumptions on that basis about the capabilities of the JavaScript language and Document Object Model now barely constitutes an adequate defensive programming approach. Instead, it is recommended that JavaScipt programmers should write code that tests for the presence of individual objects, properties and methods before attempting to use them.

The European Computer and Manufacturer’s Association (ECMA) has attempted to standardise JavaScript under the name ECMAScript. The third edition of the ECMAScript language specification was produced in December 1999.

ECMAScript

http://www.ecma.ch/ecma1/STAND/ECMA-262.htm

4.6.4.3 ActiveX

ActiveX is the name Microsoft gave to a set of ‘strategic’ object-oriented programming technologies and tools. Recent versions have changed the name to COM and most recently to DCOM.

The main thing that is created when writing a program to run in the ActiveX environment is a component, a self-sufficient program that can be run anywhere in your ActiveX network (currently a network consisting of Windows systems). This component is known as an ActiveX control. There is no full implementation of the ActiveX component run-time environment in the MacOS version of Internet Explorer.

ActiveX is Microsoft's answer to the Java technology from Sun Microsystems. An ActiveX component can be considered to be very roughly equivalent to a Java applet.

One of the main advantages of a component is that it can be reused by many applications (referred to as component containers). A COM component object (ActiveX control) can be created using one of several languages or development tools, including C++ and Visual Basic.

ECMAScript - http://www.ecma.ch/ecma1/STAND/ECMA-262.htm

4.6.5 Use of NOSCRIPT element

All browsers do not support scripts. Some firewalls do not permit their passage to the desktop and browsers behind such firewalls work with the script’s disabled. When, for example, JavaScript is used, it should not be relied on. You should,

<noscript><a href=”summary.htm”>This is a summary of alternative information.</a></noscript>

4.6.6 CGI (Common Gateway Interface) scripts

CGI (common gateway interface) scripts were the first to add interactivity to web pages. CGI is not a programming language but a specification for writing programs that enable transactions between a web server and other programs on that server. CGI applications are usually developed in the Perl scripting languages, but compiled programming languages such as, C, C++, Java, and Visual Basic are often also used.

Typical applications of CGI scripts include:

CGI scripts run as programs on the servers and therefore must be considered as potential security risks. Because of this some ISPs and commercial websites limit the use of CGI applications.

4.6.7 Document Object Model

The Document Object Model (DOM) is a browser scripting and programming interface that represents the contents of HTML documents as objects that can be manipulated by scripts and programs. Each structural element in a document (heading, paragraphs, lists etc) is available to be manipulated. Using the DOM, a programmer can write a script or program that modifies, creates, and deletes document objects dynamically from within the browser. A virtually endless array of multimedia effects can be created, and page content can be dynamically modified in response to user input. The DOM can also be used in conjunction with CSS to change the display characteristics of a page dynamically.

The DOM is in principle programming language independent. Document objects can be manipulated with JavaScript, Java, VBScript, Perl etc. In practice, JavaScript is almost always used because a language interpreter for it is installed as part of both the Internet Explorer and Netscape browsers.

In section navigation