JavaScript in HTML
Client-side JavaScript code may be embedded in HTML files in several ways:
-
<SCRIPT>tag Most JavaScript code appears in HTML files between a
<SCRIPT>tag and a</SCRIPT>tag. The<SCRIPT>tag can also be used to include an external file of JavaScript code into an HTML document. The<SCRIPT>tag supports a number of attributes, including these three important ones:
-
LANGUAGE.25i Specifies the scripting language in which the script is written. In most browsers, this attribute defaults to “JavaScript.” You must set it if you are mixing scripting languages, such as JavaScript and VBScript. Set this attribute to “JavaScript1.1” to specify that the code uses JavaScript 1.1 features, and that it should not be interpreted by JavaScript 1.0 browsers. Set this attribute to “JavaScript1.2” to specify that only JavaScript 1.2 browsers should interpret the code. (Note, however, that Navigator 4 has some nonstandard behaviors when “JavaScript1.2” is specified.)
-
SRC.25i Specifies the URL of an external script to be loaded and executed. Files of JavaScript code typically have a .js extension. Note that the
</SCRIPT>tag is still required when this attribute is used. Supported in JavaScript 1.1 and later.-
ARCHIVE.25i Specifies the URL of a JAR file that contains the script specified by the SRC attribute. Supported in JavaScript 1.2 and later. Archives are required to use Navigator 4 signed scripts.
- Event handlers
JavaScript code may also appear as the value of event handler ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access