Name

<SCRIPT> — NN 2 IE 3 HTML 4

Synopsis

<SCRIPT>...</SCRIPT>

End Tag: Required

The SCRIPT element provides a container for lines of script code written in any scripting language that the browser is capable of interpreting. Script statements that are not written inside a function definition are executed as the page loads; function definitions are loaded but their execution is deferred until explicitly invoked by user or system action (events). You can have more than one SCRIPT element in a document, and you may include SCRIPT elements written in different script languages within the same document.

An important shift in attribute syntax is introduced with HTML 4.0. To specify the scripting language of the statements within a SCRIPT element, the LANGUAGE attribute has been used since the first scriptable browsers. HTML 4.0 deprecates that attribute in favor of the TYPE attribute, whose value is a MIME type. When the TYPE attribute is widely adopted by browsers, you may want to include both attributes in documents for long-term backward compatibility with older browsers.

Newer browsers also allow script statements to be imported into the document from a document whose URL is specified for the SRC attribute. Older, nonscriptable browsers don’t recognize the SCRIPT element and may attempt to render the script statements as regular HTML content. To prevent this, wrap the script statements inside HTML block comment markers. The end-of-comment marker (-->) must be preceded by a JavaScript ...

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.