HTML and CSS Reference
In-Depth Information
FiGure 21-2
Next, note the attribute in the <script> tag:
<script type=”text/javascript”>
HTML supports numerous scripting languages, although JavaScript is by far the most popular. You
need to identify which language is to be executed through the type attribute.
It is also possible to target a specific version of JavaScript with the language
attribute, like this:
<script type=”text/javascript” language=”javascript1.5”>
However, unless your code calls for functionality specific to a certain version,
you can omit the language attribute.
Immediately following the opening <script> tag and right before its closing mate, you'll find the
code for creating an HTML comment. This practice stems from the earlier days of the Web where
browser support for JavaScript was not universal. A browser without JavaScript support would
essentially jump over the scripting language code because of the HTML comment placement. Many
web designers leave off the comment code, but others feel it is a good way to future-proof your
pages just in case as-yet-unreleased devices that do not support JavaScript appear. For me, it is sec-
ond nature and I always include them.
Finally, we arrive at the one line of JavaScript code:
document.write(Date())
This code uses a frequently applied function, document.write() that inserts a text string into the
HTML page. The text string can be plain text, HTML, a JavaScript value, or any combination
thereof. In the example, the text returned from invoking the Date() object is written to the page.
Search WWH ::




Custom Search