Language References
Specifies a script to run for the page. | HTML 4, 4.01, 5 |
HTML Syntax
<script
class = classname
defer
event = eventname
for = element
id = value
language = javascript | jscript | vbscript | vbs | xml
src = url
title = text
type = mime-type
>
A script is a type of computer code, or a set of instructions that can directly be executed by a program that understands the language in which the script is written, such as the Web browser.
The SCRIPT element specifies client-side script code, or specifically ECMA-standard JavaScript code that can be run directly in the browser, and is inserted directly into the HTML page.
Although SCRIPT elements can in theory be placed anywhere in the HTML page, functions in the SCRIPT element that will need user interaction must be placed in the HEAD of the document, as then the functions will be available to the document as it is loaded.
SCRIPT to be executed in a certain part of the document must be inserted in the appropriate place in the document BODY where the code will act upon.
Code within the SCRIPT block that is not contained within a function is executed immediately as the page is loaded.
The SCRIPT element can also be used to insert and run code from an external JavaScript file, using the src attribute.
To keep scripts from being displayed on down-level browsers, the SCRIPT block should be nested within a COMMENT block.
The NOSCRIPT element can be used to provide content that is displayed by browsers for which JavaScript is not available, while being ignored by browsers that can understand JavaScript. For example, authors can use NOSCRIPT to provide a warning that the page requires JavaScript.
A SCRIPT element appearing after a FRAMESET element is ignored.
Please see the chapter on Basic Scripting for detailed information on how JavaScript can be used to enhance Web pages.
SCRIPT Members
Implementing JavaScript in HTML