SCRIPT Element


Netscape introduced a SCRIPT element, for use in both the document HEAD and BODY. This can contain an executable script, written in JavaScript, which is Netscape's cross platform, object-based scripting language.

JavaScript script programs can add interaction and dynamic functionality to your web pages. Be careful. Remember that some users do not have access to browsers that support JavaScript, so they will not be able to use these scripts.

The <SCRIPT> tag is an extension to HTML that can enclose any number of JavaScript statements as shown below:

    <SCRIPT>
	JavaScript statements...
    </SCRIPT>
The optional LANGUAGE attribute specifies the scripting language and JavaScript version:
    <SCRIPT LANGUAGE="JavaScriptVersion">
	JavaScript statements...
    </SCRIPT>
where JavaScriptVersion specifies one of the following to indicate which version of JavaScript your code is written for:

Statements within a <SCRIPT> tag are ignored if a browser does not have the level of JavaScript support.

To ensure that other browsers which do not support JavaScript ignore the code so it does not appear in your web page, place the entire script within HTML comment tags, and precede the ending comment tag with a double slash (//) that indicates a JavaScript single-line comment:

    <SCRIPT>
    <!-- Hide the scripting from non-supporting browsers.
    JavaScript statements...
    // End of hiding here. -->
    </SCRIPT>

Since browsers typically ignore unknown tags, non-JavaScript-capable browsers will ignore the beginning and ending SCRIPT tags. All the script statements are enclosed in HTML comment tags, so they are ignored too.

Use the <NOSCRIPT> and </NOSCRIPT> tags to specify alternate content for browsers that do not support JavaScript. HTML enclosed within a <NOSCRIPT> tag is displayed by browsers that do not support JavaScript; code within the tags are ignored by Netscape. Note however, that if the users has disabled JavaScript by choosing Network Preferences from the Options menu, Netscape displays the code within the <NOSCRIPT> tags.

The following shows an example using the <NOSCRIPT> tags:

Commence scripting...
<SCRIPT LANGUAGE="JavaScript">
<!--
document.writeln("<BR>This text should show up if the ");
document.writeln("browser is JavaScript enabled.");
document.writeln("<BR><BR>");
// -->
</SCRIPT>
<NOSCRIPT>
<H3 ALIGN="center">
You need to use a JavaScript enabled browser to see 
JavaScript code here.
</H3>    
</NOSCRIPT>
Scripting terminated.
Example Picture

Teaching JavaScript itself is beyond the scope of this course. However, you can download a handbook for JavaScript from Netscape if you wish to pursue this language further.