What are Scripts?

A script is a program, that can run as part of a web page (or as a separate file) to perform simple changes to the page or execute complicated functions.

As you become more confident writing your web pages you may want to add some special extra facilities to your site with scripts. Even a simple bit of code can produce some clever and interesting effects. There are several script languages, but the most common client-side script (i.e.: it is executed on the PC of the person browsing, not on the host computer) that works on most browsers is JavaScript.

The use of "Java" in JavaScript should not confuse anyone that this is the Java language. Java is a programming language designed by Sun Microsystems. They collaborated with Netscape who had written a language called "LiveScript", and combined elements of both to produce JavaScript.

JavaScript version 1.0 first appeared in their Navigator 2.0 browser and has appeared in all subsequent browsers from Netscape. There are now several versions of JavaScript supported by various browsers and browser versions. This often leads to confusion and incompatibilities.

Microsoft attempted to support JavaScript 1.0 in their Internet Explorer 3.0 browser calling it "JScript", however it was unreliable. They introduced their own scripting language "VBScript" in Internet Explorer 3.0, but it is not supported in Netscape browsers without a proprietary plug-in. Internet Explorer 4.0 includes good support for the standardised JavaScript, although it is very similar to Netscape's JavaScript 1.2, it is not exactly equivalent.

JavaScript Example: Status Bar Clock.

The simple piece of JavaScript below is written into this web page, so you should see a date and time display in the status bar at the bottom of the browser window. JavaScript code is usually placed in the <head> section of the HTML, but depending on the use JavaScript can be placed in the <body> section of the document.

<script language="JavaScript">

This tells the browser this is the start of a segment of JavaScript.

<!-- Begin
function runClock() {

The <!-- stops the code appearing on the screen in browsers that do not interpret scripts.

theTime = window.setTimeout("runClock()", 1000);
var today = new Date();
var display = today.toLocaleString();
status=display;
}

This is the main part of the script, setting variables and giving the browser instructions on what to do.

// End -->
</script>

Finally this tells the browser this is the end of a segment of script.

<body onLoad="runClock()">

Adding the extra bit of code to the <body> tag tells the browser to execute the script. The result should look like the snapshot below.

This Free JavaScript provided by
JavaScript Source
http://javascript.internet.com Link opens in a new window

image of JavaScript clock demo

Java Script Resources: