<SCRIPT>...</SCRIPT>
Description
This element adds the possibility of programming inside a HTML document by
using a scripting language. The functions are programmed inside the SCRIPT
container.
This element can be used in the HEAD and
BODY section of the document.
To keep older browsers, that do not support scripting, from displaying the
source of the scripts it is a common use to comment the contents of the
SCRIPT element, like this:
 |
<SCRIPT language="JavaScript">
<!-- Hide contents from older browsers
function ShowMessage(Msg) {
alert(Msg)
}
// End hiding the contents -->
</SCRIPT>
|
DTD
<!ELEMENT SCRIPT - - %Script; -- script statements -->
<!ATTLIST SCRIPT
charset %Charset; #IMPLIED -- char encoding of linked resource --
type %ContentType; #REQUIRED -- content type of script language --
language CDATA #IMPLIED -- predefined script language name --
src %URI; #IMPLIED -- URI for an external script --
defer (defer) #IMPLIED -- UA may defer execution of script --
>
from the
HTML 4.0 DTD,
"Copyright ©
W3C,
(MIT,
INRIA,
Keio).
All Rights Reserved."
Attributes
CHARSET
This attribute specifies the character encoding used to write the script.
DEFER
With this attribute you can signal to the browser that this script doesn't
generate content that must be included dynamically in the document. In
JavaScript this is done with the document.write()
function. That
way the browser knows that the script doesn't influence the initial rendering
of the page, and this may speed up viewing the document.
LANGUAGE
Determines the programming language that is used. Possible values are
JavaScript, developed by
Netscape
.
This language is also supported by Internet Explorer, but there are certain
differences between the support and interpretation of a script. So test
thoroughly...
With every new version of Netscape Navigator additions are made to the
JavaScript language. This means that not every version has the same scripting
capabilities. To be sure the browser can handle a script there is a way to
specify which version of JavaScript is needed. This is done by a different
value for this attribute.
language="JavaScript"
is supported by Navigator 2.0, and
Internet Explorer 3.0, language="JavaScript1.1"
is
available in Navigator 3.0 and language="JavaScript1.2"
is available in Navigator 4.0.
If you write a script that uses features of a higher version you can
anticipate to browsers that don't support that version. If you include a
function with the same name, but in another SCRIPT element, using a different
language each browser version will pick the script version it can execute. But
you must put the highest version first in the page, followed by older versions.
For example:
<HEAD>
<SCRIPT language="JavaScript1.2">
function yourFunction() {
// The version which uses 1.2 features.
}
</SCRIPT>
<SCRIPT language="JavaScript1.1">
function yourFunction() {
// The version which uses 1.1 features.
}
</SCRIPT>
<SCRIPT language="JavaScript">
function yourFunction() {
// The basic version.
}
</SCRIPT>
</HEAD>
Microsoft
developed VBScript, a scripting language based on Visual Basic. This language
is only available in Internet Explorer.
SRC
This attribute lets you specify a file as the script source (rather than
embedding the script in the HTML). Script statements in a SCRIPT element with a
SRC attribute are ignored. Note, however, that the closing </SCRIPT>
element is required.
TYPE
Defines the language being used for this script. You must supply a MIME-type
for this attribute. Some known values are text/javascript and text/vbscript.
This attribute replaces the deprecated language attribute.
Examples
 |
<SCRIPT language="JavaScript">
function RunExample() {
alert('You pushed the button!');
}
</SCRIPT>
<FORM>
Push the button to show an alert box with a message.<BR>
<INPUT type="button" value="Run example" onclick="RunExample()">
</FORM>
|
|
 |
|