ⓘ script – embedded script # T
The
script
element
enables dynamic script and data blocks to be included in documents.
Permitted attributes #
-
ⓘ
global attributes
- Any attributes permitted globally.
-
ⓘ
type =
MIME type
#
- The language of the script or format of the data.
A string that identifies a valid
MIME media type
as defined in
[RFC 2046].
-
ⓘ
language = string OBSOLETE
#
- Specifies that the language of the script is JavaScript.
-
ⓘ
src =
non-empty URL potentially surrounded by spaces
#
- The address of the external script to use.
-
ⓘ
defer =
"defer" or "" (empty string) or empty
#
- Specifies that script should be executed after the
document has been parsed.
-
ⓘ
async =
"async" or "" (empty string) or empty
NEW
#
- Specifies that the script should be executed
asynchronously, as soon as it becomes available.
-
ⓘ
charset =
character encoding name
#
- The character encoding of the external script.
Additional constraints and admonitions #
- A script element must not
contain an occurrence of the character sequence
"
<!--
" without a matching later occurrence
of the character sequence "-->
".
- A
script
element with a
src attribute must contain only:
- lines that consist solely of a newline, optionally
preceded by one or more space (U+0020) characters or tab
(U+0009) characters
- single-line comments, which are lines
beginning with the character sequence "
//
",
optionally preceded by one more more
space (U+0020) characters or tab (U+0009) characters,
followed by any
number of characters that are not a newline, and ending with
a newline
- multi-lines comments, which begin with the character
sequence
"
/*
",
optionally preceded by one more more space (U+0020)
characters or tab (U+0009) characters, and that end with
the character sequence
"*/
"
-
Element script with attribute language whose value is “JavaScript”
must not have attribute type whose value is not
“text/javascript”.
-
Element script must not have attribute charset unless attribute src is
also specified.
-
Element script must not have attribute defer unless attribute src is
also specified.
-
Element script must not have attribute async unless attribute src is
also specified.
-
The language attribute on the script element is obsolete.
Use the type attribute instead.
-
The language attribute on the script element is obsolete. You can safely omit it.
Permitted parent elements #
any element that can contain
metadata elements, any element that can contain
phrasing elements
DOM interface #
interface HTMLScriptElement : HTMLElement {
attribute DOMString src;
attribute boolean async;
attribute boolean defer;
attribute DOMString type;
attribute DOMString charset;
attribute DOMString text;
};
Typical default display properties #