This element encloses statements in a scripting language for client-side processing. Scripting statements can either be included inline or loaded from an external file and might be commented out to avoid execution by nonscripting-aware browsers.
id="unique alphanumeric identifier"
language="scripting language name"
src="url of script code"
Attributes Defined by Internet Explorer
event="event name" (3)
for="element ID" (3)
Events Defined by Internet Explorer
onload, onpropertychange, onreadystatechange
Element Specific Attributes
- This attribute defines the character encoding of the script. The value is a space- and/or comma-delimited list of character sets as defined in RFC 2045. The default value is ISO-8859-1.
- Presence of this attribute indicates that the browser might defer execution of the script enclosed by the <script> element. In practice, deferring code might be more dependent on the position of the <script> element or the contents. This attribute was added very late to the HTML 4.01 specification and its support is currently minimal.
- This Microsoft attribute is used to define a particular event that the script should react to. It must be used in conjunction with the for attribute. Event names are the same as event handler attributes; for example, onclick, ondblclick, and so on.
- The for attribute is used to define the name or ID of the element to which an event defined by the event attribute is related. For example, <script event="onclick" for="button1" language="vbscript"> defines a VBScript that will execute when a click event is issued for an element named button1.
- This attribute is included from XHTML 1.0 on, and is used to set whether spaces need to be preserved within the script element or whether the default white space handling should be employed. In practice, this attribute is not used by developers.
<!-- alert("Hello World !!!"); // -->
<!-- code in external file -->
HTML 4 and 4.01, XHTML 1.0, 1.1
Internet Explorer 3, 4, 5, 5.5, 6
Netscape 2, 3, 4, 4.5-4.8, 6, 7
<!-- Javacript code here // -->
<script language="vbscript">The HTML 3.2 specification defined a placeholder <script> element.
<!-- VBScript code here -->
The event and for attributes are defined under transitional versions of HTML 4.01 but only as reserved values. Later specifications appear to have dropped potential support for them, though they continue to be supported by Internet Explorer.
Refer to the <noscript> tag reference in this appendix to see how content might be identified for nonscripting-aware browsers.