HTML and CSS Reference
In-Depth Information
type This attribute should be set to the MIME type corresponding to the scripting language
used. For JavaScript, for example, this would be text/javascript . In practice, the
language attribute is more commonly used, but the type attribute is standard. When not
specified, the default value is text/javascript . There is indication that it should actually
be application/javascript , but given that browser support for this value is not
consistent it is dangerous to use. Also, it is possible to indicate version information in the
type attribute for certain browsers; for example, to indicate JavaScript 1.8 you would use
<script type="application/javascript;version=1.8"> .
xml:space This attribute is included from XHTML 1.0 and is used to set whether spaces
need to be preserved within the script element or the default whitespace handling should
be employed. In practice, this attribute is not often used by developers.
Examples
<script type="text/javascript">
alert("Hello World !!!");
</script>
<!-- code in external file -->
<script language="JavaScript1.2" src="superlib.js"></script>
Compatibility
HTML 4, 4.01, 5
XHTML 1.0, 1.1
Firefox 1+, Internet Explorer 3+,
Netscape 2+, Opera 4+, Safari 1+
Notes
• It is common practice to comment out statements enclosed by a <script> tag.
Without commenting, script code can be displayed as page content by user agents
that do not support scripting. The particular comment style might be dependent on
the language being used. For example, in JavaScript, use
<script type="text/javascript">
<!--
JavaScript code here
// -->
</script>
In VBScript, use
<script type="text/vbscript">
<!--
VBScript code here
-->
</script>
XML escapes using CDATA sections are also possible; however, in all cases it is better
to avoid intermixing script code in a markup document and instead to link to it.
• The HTML 3.2 specification defined a placeholder script element.
• The event and for attributes are defined under transitional versions of HTML 4.01
but only as reserved values. Later specifications appear to have dropped potential
support for them, though they continue to be supported by Internet Explorer.
Search WWH ::




Custom Search