Browsers tend to cope with incorrect HTML but they are much more fussy about JavaScript. Take great care to type the program examples exactly as shown. Pay attention to letter cases, spacing and punctuation. If it doesn't work, that kind of thing should be checked first.
Start a new file in your text editor:
function showDateTime ()
{
var now = new Date ();
document.write ("It is now " + now);
}
Then edit your index.html file from the first exercise:
onload="showDateTime()"
Open the new version of index.html in your browser. In most browsers you should see something like this:
However, if you are using Microsoft's Internet Explorer (IE) you are more likely to see this:
Microsoft's reason for this is that an HTML page displayed from disc may have been saved there from a web site and therefore may pose a security threat if it contains any kind of program (not just HTML). In our case the warning is just an irritation that is thwarting our attempt to run a simple program.
Fortunately there is a simple solution. Enter this as a new line at the start of index.html, before the start of the html tag:
<!-- saved from url=(0014)about:internet -->
From now on include that line before the opening html tag for every HTML page you write and everything will work in IE without unnecessary warning messages.
More about that extra line, which is known as MOTW (the Mark Of The Web), can be found on microsoft.com, here.
See the next page.