Script

Support Key: [2|3|3.2*|4] [X1|X1.1] [IE3B1|M|N2B3|O3]
What is it?
Attributes
Tag Example
Parent/Content Model
Tips & Tricks
Browser Peculiarities
= Index DOT Html by Brian Wilson =
Main Index | Element Tree | Element Index | HTML Support History



   Quick Statistics   
End Tag:
   Required
Standards Details:
In all HTML 4.x/XHTML DTDs
XHTML Modules:
Scripting
CSS 'display' Type:
NA
CSS Mapping:
NA
Default Rendering:
NA
Official Docs:
HTML 4.x, XHTML 1.1

What is it?
The SCRIPT element is the method used by browsers to recognize scripting languages in an HTML document. Scripting (both embedded and external to the page) allows web pages to perform actions and change dynamically in response to events such as screen exit and entry, or user mouse-clicks.

While discussing the full scope of scripting in HTML pages is not the intent of these documents, discussion of how scripting affects HTML authoring is DEFINITELY relevant. Many other sites have covered the details of scripting languages with far greater skill and detail than I could ever manage. Please see the Related Links section for pointers to good resources on the subject.
JavaScript and Other Scripting Languages
The most popular browser scripting language at this time is the JavaScript language from Netscape. The JavaScript language has been standardized by ECMA as ECMA-262, (AKA EcmaScript.) Microsoft has also implemented a version of the JavaScript language under the name JScript.

While JavaScript is the most widely implemented scripting language, it is possible to use any language, provided the browser you are using can understand it. Microsoft, for example, also makes a scripting language for the Internet Explorer browser called VBScript (based on the Visual Basic programming language) and a few other languages (such as Perl) are also usable with some web browsers.
Event Handlers and Script Invocation
Scripting code can be invoked either as a function call to a routine contained in the SCRIPT element or the scripting language statements can be included in-line within the attribute value of the attribute that invokes it.

To allow scripting to interact dynamically with web page elements, a class of HTML attributes were added called "Event Handlers." These HTML attributes (there are now over 50 different events) trigger script code when the action/event that they are bound to occurs for an element.

Javascript allows an extra type of event trapping beyond event handlers. The A HREF element can also be used to invoke script code. The script is run when the user activates the hyperlink (see the A HREF page for more details.)

Common Attributes
%Core%
[2|3|3.2|4] [X1|X1.1] [IE4|M|N4|O5]
%Accessibility%
[2|3|3.2|4] [X1|X1.1] [IE4|M|N|O]

Specific Attributes
Archive
[2|3|3.2|4] [X1|X1.1] [IE|M|N4|O]
Standards Details: NA
Required? No
Description:
This attribute specifies an archive file containing the external script file necessary for use in the current document.
Values: Either an absolute or relative URL to a Java ARchive (.jar) file. All URLs should be URL encoded where required.
Charset
[2|3|3.2|4] [X1|X1.1] [IE|M|N7|O7]
Standards Details: In all HTML 4.x/XHTML DTDs
Required? No
Description:
This indicates the character encoding of the script contents.
Values: CDATA. [A recognized RFC 2045 language character set string. Default is ISO-8859-1.]
Defer
[2|3|3.2|4] [X1|X1.1] [IE4|M|N|O??]
Standards Details: In all HTML 4.x/XHTML DTDs
Required? No
Description:
This stand alone attribute is used to advise the browser that the script is not going to generate any rendered document content and thus, the user agent can continue parsing and rendering.
Values: NA (HTML); defer (XHTML)
Event
[2|3|3.2|4] [X1|X1.1] [IE4|M|N|O]
Standards Details: Added in HTML 4.01. Present in all HTML 4.01 DTDs. Dropped in XHTML DTDs
Required? No
Description:
Specifies the event the script is being written for.
Values: CDATA. [Event name]
For
[2|3|3.2|4] [X1|X1.1] [IE4|M|N|O]
Standards Details: Added in HTML 4.01. Present in all HTML 4.01 DTDs. Dropped in XHTML DTDs
Required? No
Description:
Specifies which element is being bound to the event script.
Values: CDATA. [A scripting object or element ID.]
Language
[2|3|3.2|4] [X1|X1.1] [IE3B1|M|N2B3|O3]
Standards Details: Deprecated in HTML 4.x/XHTML 1.0. Dropped in XHTML 1.1.
Required? No
Description:
This attribute indicates the scripting language the script is written in. It is required if the SRC attribute is not specified, optional otherwise.
Values: CDATA. [The two most popular scripting languages currently are JavaScript and VBScript]
Src
[2|3|3.2|4] [X1|X1.1] [IE3.02|M|N3B5|O3]
Standards Details: In all HTML 4.x/XHTML DTDs
Required? No
Description:
This attribute specifies an external source for the script code.
Values: CDATA. [Either an absolute or relative URL. All URLs should be URL encoded where required.]
Type
[2|3|3.2|4] [X1|X1.1] [IE4|M|N4|O]
Standards Details: In all HTML 4.x/XHTML DTDs
Required? Yes
Description:
This attribute specifies the MIME type of the scripting code.
Values: CDATA. [Alphanumeric MIME type]
xml:space
[2|3|3.2|4] [X1|X1.1] [IE|M|N|O]
Standards Details: Intrinsic part of XML
Required? No
Description:
This is a basic XML syntax that keeps all whitespace characters intact when they are parsed. Spacing characters are almost always an important part of script syntax and string processing, so including this attribute in the standards for this element makes sense.
Values: preserve - maintain all whitespace characters in rendering and data storage (including multiple spaces, tabs, carriage returns and linefeeds.)
Example
<html>
<head>
   <script language="JavaScript" type="text/javascript">
      <!-- hide script from old browsers
      function getname(str) {
      alert("Hi, "+ str + "!");
      }
      // end hiding contents -->
   </script>
</head>
<body>
   Please enter your name:
   <form>
      <input type="text" name="name" onblur="getname(this.value)" value="" />
   </form>
</body>
</html>
Parent Model
%In-line Parent% | %Block Parent% | <Head>
Content Model
%Text% | <!-- -->
Tips & Tricks Browser Peculiarities
Boring Copyright Stuff...