(may) A client-side script is a program that may accompany an HTML document or be embedded directly in it. The program executes on the client's machine when the document loads, or at some other time such as when a link is activated. HTML's support for scripts is independent of the scripting language.
(author)(may) There are two types of scripts authors may attach to an HTML document:
1. Those that are executed one time when the document is loaded by the user agent. Scripts that appear within a SCRIPT element are executed when the document is loaded. For user agents that cannot or will not handle scripts, authors may include alternate content via the NOSCRIPT element.
2. Those that are executed every time a specific event occurs. These scripts may be assigned to a number of elements via the intrinsic event attributes.
(must) SCRIPT: type = content-type [CI]
This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript").
(must)(deprecated) SCRIPT: language = cdata [CI]
Deprecated. This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type.
(must) SCRIPT: defer [CI]
When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.
(informative) 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.
(should) User agents should determine the default scripting language for a document according to the following steps (highest to lowest priority):
1. If any META declarations specify the "Content-Script-Type", the last one in the character stream determines the default scripting language.
2. Otherwise, if any HTTP headers specify the "Content-Script-Type", the last one in the character stream determines the default scripting language.
(author)(must) Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect.
(informative) Each scripting language has its own conventions for referring to HTML objects from within a script. This specification does not define a standard mechanism for referring to HTML objects.
(should) Scripts should refer to an element according to its assigned name. Scripting engines should observe the precedence rules (described in 18.2.3)when identifying an element: a name attribute takes precedence over an id if both are set. Otherwise, one or the other may be used.
(author)(informative) Authors of HTML documents are advised that changes are likely to occur in the realm of intrinsic events (e.g., how scripts are bound to events). Research in this realm is carried on by members of the W3C Document Object Model Working Group (see the W3C Web Site at http://www.w3.org/ for more information).
(must) Intrinsic events: onfocus = script [CT]
The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation.
(must) Intrinsic events: onfocus = script [CT]
This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.
(must) Intrinsic events: onblur = script [CT]
The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation.
(must) Intrinsic events: onchange = script [CT]
The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.
(may) 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" statement in the HTML object model supported by some vendors).
(may) The dynamic modification of a document may be modeled as follows:
1. All SCRIPT elements are evaluated in order as the document is loaded.
2. All script constructs within a given SCRIPT element that generate SGML CDATA are evaluated. Their combined generated text is inserted in the document in place of the SCRIPT element.
3. The generated CDATA is re-evaluated.
(should) The content of a NOSCRIPT element should only be rendered by a script-aware user agent in the following cases:
1. The user agent is configured not to evaluate scripts.
2. The user agent doesn't support a scripting language invoked by a SCRIPT element earlier in the document.
(should) Some scripting engines, including those for languages JavaScript, VBScript, and Tcl allow the script statements to be enclosed in an SGML comment. User agents that don't recognize the SCRIPT element will thus ignore the comment while smart scripting engines will understand that the script in comments should be executed.
(should) One of solution to the problem that user agents don't recognize the script element is to keep scripts in external documents and refer to them with the src attribute.
(should) The JavaScript engine allows the string "<!--" to occur at the start of a SCRIPT element, and ignores further characters until the end of the line. JavaScript interprets "//" as starting a comment extending to the end of the current line. This is needed to hide the string "-->" from the JavaScript parser.
(should) In VBScript, a single quote character causes the rest of the current line to be treated as a comment. It can therefore be used to hide the string "-->" from VBScript.
(author)(should) Some browsers close comments on the first ">" character, so to hide script content from such browsers, you can transpose operands for relational and shift operators (e.g., use "y < x" rather than "x > y") or use scripting language-dependent escapes for ">".