This section is normative.
The Scripting Module defines elements that are used to contain information pertaining to executable scripts or the lack of support for executable scripts. Elements and attributes included in this module are:
|Elements||Attributes||Minimal Content Model|
|noscript||Common||(Heading | List | Block)+|
|script||charset (Charset), declare ("declare"), src (URI), type* (ContentType), xml:space="preserve"||PCDATA | script | noscript|
When this module is used, the script and noscript elements are added to the Block and Inline content sets of the Text Module. In addition, the script element is added to the content model of the head element defined in the Structure Module.
The noscript element allows authors to provide alternate content when a script is not executed. The content of a noscript element will be rendered if and only if the containing script is not processed. noscript elements that are not contained in a script element will only be rendered in the following cases:
User agents that do not support client-side scripts must render this element's contents.
In the following example, a user agent that executes the script will include some dynamically created data in the document. If the user agent doesn't support scripts, the user may still retrieve the data through a link.
<script type="text/tcl" src="http://example.org/script"> <noscript> <p>Access the <a href="http://example.org/data">data.</a></p> </noscript> </script>
The script element places a script within a document. This element may appear any number of times in the head or body of an XHTML document.
The script may be defined within the contents of the script element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the script element.
Scripts are evaluated by script engines that must be known to a user agent.
A user agent must interpret a script element according to the following precedence rules:
The syntax of script data depends on the scripting language.
As XHTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script. This may be done either through a default declaration or a local declaration.
The type attribute must be specified for each script element instance in a document.
Scripts that are executed when a document is loaded may be able to modify the document's contents dynamically. The ability to do so depends on the scripting language itself (e.g., the "document.write" method in the HTML DOM [DOM]).
The dynamic modification of a document may be modeled as follows:
XHTML documents are constrained to conform to the XHTML DTD both before and after processing any script elements.
The following example illustrates how scripts may modify a document dynamically. The following script:
will produce the following document after evaluation: