<script language=”VBScript”>
function foryou
msgbox (“A message for you!”)
end function
</script>
If you want to keep your script out of the HTML and in a separate file, use the
srcattribute, like this:
<script type=”text/javascript” src=”foryou.js”></script>
Ensure that your script file, in ordinary text format like from Notepad, is in
the same directory as the .htm file holding the HTML code. The script is
imported when the page is loaded, just as images are imported with the
<img>element.
Executing Scripts Automatically upon Loading ......................................
In the preceding examples, the user must click a button before the script exe-
cutes. If you want the script to execute when the page first loads, just remove
the function. In VBScript, that means removing two lines (functionand end
function), like this:
<script language=”VBScript”>
msgbox (“A message for you!”)
</script>
JavaScript employs braces to indicate the start and end of a procedure, so
remove both of the lines containing the braces to make a script execute when
the page first loads:
<script>
alert(“Hello, HTML world!”);
</script>
282 Part IV: Advanced CSS Techniques