<SCRIPT>NN 2   IE 3   HTML 4
<SCRIPT>...</SCRIPT>End Tag: Required
 

The SCRIPT element provides a container for lines of script code written in any scripting language that the browser is capable of interpreting. Script statements that are not written inside a function definition are executed as the page loads; function definitions are loaded but their execution is deferred until explicitly invoked by user or system action (events). You can have more than one SCRIPT element in a document, and you may include SCRIPT elements written in different script languages within the same document.

An important shift in attribute syntax is introduced with HTML 4.0. To specify the scripting language of the statements within a SCRIPT element, the LANGUAGE attribute has been used since the first scriptable browsers. HTML 4.0 deprecates that attribute in favor of the TYPE attribute, whose value is a MIME type. When the TYPE attribute is widely adopted by browsers, you may want to include both attributes in documents for long-term backward compatibility with older browsers.

Newer browsers also allow script statements to be imported into the document from a document whose URL is specified for the SRC attribute. Older, nonscriptable browsers don't recognize the SCRIPT element and may attempt to render the script statements as regular HTML content. To prevent this, wrap the script statements inside HTML block comment markers. The end-of-comment marker (-->) must be preceded by a JavaScript comment marker (//) to prevent JavaScript from generating a script error.

 
Example
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
function howdy() {
    alert("Hello, world!")
}
//-->
</SCRIPT>
CHARSETNN n/a   IE n/a   HTML 4
CHARSET="characterSet"Optional
 

Character encoding of the content in the file referred to by the SRC attribute.

 
Example
<SCRIPT CHARSET="csISO5427Cyrillic" SRC="moscow.js"></SCRIPT>
 
Value
Case-insensitive alias from the character set registry (ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets).
 
Default Determined by browser.
DEFERNN n/a   IE 4   HTML 4
DEFEROptional
 

The presence of the DEFER attribute instructs the browser to render regular HTML content without looking for the script to generate content as the page loads. This is an advisory attribute only. The browser doesn't have to hold up rendering further HTML content as it parses the content of the SCRIPT element in search of document.write() statements.

 
Example
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" DEFER>
...
</SCRIPT>
 
Value
The presence of this attribute sets its value to true.
 
Default false
 
Object Model Reference
IE [window.]document.all.elementID.defer
EVENTNN n/a   IE 4   HTML n/a
EVENT="eventName"Optional
 

Internet Explorer 4's event model allows binding of object events to SCRIPT elements with the help of the EVENT and FOR attributes. As the page loads, the browser registers each SCRIPT element with its event and object binding so that when the object generates the event, the script statements inside the SCRIPT element execute--without having to write event handlers for the objects or wrap the script statements inside function definitions. Event values are written either as unquoted event names or as quoted event names formatted as functions (with trailing parentheses and optional parameter names). Use this type of script-event binding only in Internet Explorer. Navigator attempts to execute the script statements while the page loads.

 
Example
<SCRIPT FOR=window EVENT=onresize>
...
</SCRIPT>
 
Value
Case-sensitive event name (unquoted) or the event name as a function inside a quote pair. The object described in the FOR attribute must support the event named in the EVENT attribute.
 
Default None.
 
Object Model Reference
IE [window.]document.all.elementID.event
FORNN n/a   IE 4   HTML n/a
FOR=elementIDOptional
 

Internet Explorer 4's event model allows binding of object events to SCRIPT elements with the help of the EVENT and FOR attributes. As the page loads, the browser registers each SCRIPT element with its event and object binding so that when the object generates the event, the script statements inside the SCRIPT element execute--without having to write event handlers for the objects or wrap the script statements inside function definitions. Use the unique ID attribute value of the element whose event you wish to handle. Use this type of script-event binding only in Internet Explorer. Navigator attempts to execute the script statements while the page loads.

 
Example
<SCRIPT FOR=firstNameEntry EVENT="onChange()">
...
</SCRIPT>
 
Value
Case-sensitive ID value of the event-generating element, unquoted. The object described in the FOR attribute must support the event named in the EVENT attribute.
 
Default None.
 
Object Model Reference
IE [window.]document.all.elementID.htmlFor
LANGUAGENN 2   IE 3   HTML 4
LANGUAGE="scriptingLanguage"Optional
 

Sets the scripting language for script statements defined in the element. This attribute is deprecated in HTML 4.0 (in favor of the TYPE attribute), but it has been so widely used since the first days of scriptable browsers that its use and support will continue for a long time to come.

 
Example
<SCRIPT LANGUAGE="JavaScript">
...
</SCRIPT>
 
Value
Internet Explorer recognizes four case-insensitive language names: JAVASCRIPT | JSCRIPT | VBS | VBSCRIPT. Navigator recognizes only JAVASCRIPT. Versions of JavaScript are also supported in appropriate browsers. To keep the attribute values one-word identifiers, the version numbers are tacked onto the end of the "JavaScript" language name. The version-less "JavaScript" is observed by all browsers; "JavaScript1.1" is recognized only by Navigator 3; "JavaScript1.2" is recognized by Navigator 4 and Internet Explorer 4. When SCRIPT elements are assigned these later version values, older browsers that don't support the named version ignore the SCRIPT elements.
 
Default JavaScript
 
Object Model Reference
IE [window.]document.all.elementID.language
SRCNN 3   IE 4   HTML 4
SRC="URL"Optional
 

Imports a file of script statements from an external file. Once the external statements are loaded, the browser treats them as if they were embedded in the main HTML document. This attribute had some support in Internet Explorer 3, but it relied on a specific JScript.dll version, which makes it unreliable to blindly use it in IE 3.

In theory, you should be able to add script statements inside a SCRIPT element that loads an external script library file. In practice, it is more reliable to provide a separate SCRIPT element for each external library file and for in-document scripts.

Current implementations limit the SRC attribute to point to JavaScript external files. Such files must have a .js filename extension, and the server must have the extension and application/x-javascript MIME type set to serve up such files.

 
Example
<SCRIPT LANGUAGE="JavaScript" SRC="stringParseLib.js"></SCRIPT>
 
Value
Any valid URL. Current browsers require files whose names end in the .js extension. A complete URL may help overcome difficulties in some earlier browsers that implement this feature.
 
Default None.
 
Object Model Reference
IE [window.]document.all.elementID.src
TYPENN n/a   IE 4   HTML 4
TYPE="elementType"Required
 

An advisory about the content type of the script statements. The content type should tell the browser which scripting engine to use to interpret the script statements. The TYPE attribute may eventually replace the LANGUAGE attribute as the one defining the scripting language in which the element's statements are written. To be compatible with future and past browsers, you may include both the LANGUAGE and TYPE attributes in a SCRIPT element.

 
Example
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
...
</SCRIPT>
 
Value
Case-insensitive MIME type. Values are limited to one(s) for which a particular browser is equipped.
 
Default text/javascript in Internet Explorer 4.
 
Object Model Reference
IE [window.]document.all.elementID.type
Hosted by uCoz