Scripting
This element is used to enclose a script that is to be ran by the browser. It is typically used for JavaScript and VBScript. An enclosed script may be either typed in as the content of this element, or included from an external file. This element is often combined with the no script element.
<script
charset="charset code"
defer
language="text"**
src="url"
type="MIME type"
>
</script>
Key:
‡ = Required attribute
** = Transitional only
Explanation of attributes
charset: used to define the character encoding of the external script file. The value of this attribute is a code specified in RFC 2045, for example UTF-8 or ISO-8859-1. The default value of this attribute is ISO-8859-1.
defer: this attribute can be used to indicate that the script should not be ran straight away, but execution should be deferred until the rest of the document has been loaded and rendered by the browser. In practice, this attribute has little support amongst browsers.
language**: this attribute is used to indicate the language that the script is written in. Although a deprecated attribute, many older browsers do not support the type attribute and so may rely upon this - in reality these older browsers are rarely used. Common values for this attribute include JavaScript, JavaScript1.1 and VBScript. It should also be noted that some older browsers will use this attribute to determin the version of the language the script is written in and will not attempt to execute versions they do not understand.
src: this attribute is used to specify an external file that contains the script to be run. If this attribute is used, then the content of this element is ignored by the browser in favor of the external script.
type: this attribute specifies the MIME type of the script, that is what language the script is written in. The most popular value of this attribute is text/javascript indicating that the script is JavaScript.
Event handlers
No event handlers are defined for this element.
Basic example
<script type="text/javascript"> <!-- document.write("Hello World!"); //--> </script>
The above code will allow the execution of the JavaScript contained within it. In this case, it will result with the text "Hello World" being printed to the browser window.
Compatibility
| Test | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|---|
| Basic element support | |
|
|
|
|
|
| Attribute: charset | |
|
|
|
|
? |
| Attribute: defer | |
|
|
|
|
? |
| Attribute: language | |
|
|
|
|
|
| Attribute: src | |
|
|
|
|
|
| Attribute: type | |
|
|
|
|
? |
Key:
The browser icons are explained in the below list:
= Microsoft Internet Explorer 6+
= Netscape Communicator 4
= Mozilla and Netscape Navigator 6+
= Opera 7+
= MSN TV (aka. WebTV)
= Konqueror 3.0+