Java Reference
In-Depth Information
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<title>Untitled Document</title>
</head>
<body>
<h2 align=center>Here's what's new on this website</h2>
</body>
</html>
Save this page as
WhatsNew.htm.
Load MainPage.htm into a browser. The fi rst time you go to the main page, there will be nothing but
a heading saying “Welcome to my website.” Obviously, if this were a real web site, it would have a bit
more than that, but it suffi ces for this example. However, refresh the page and suddenly you'll see the
page shown in Figure 11-13.
Figure 11-13
If you click the image you're taken to the
WhatsNew.htm
page detailing all the things added to the web
site since you last visited. Obviously nothing has actually changed in your example web site between
you loading the page and then refreshing it. You got around this for testing purposes by setting the
date when the web site last changed, stored in variable
lastUpdated
, to a date in the future (here,
December 28, 2020).
The WhatsNew.htm page is just a simple HTML page with no script, so you will confi ne your attention
to MainPage.htm. In the head of the page in the fi rst script block, you declare the variable
lastUpdated.
var lastUpdated = new Date(“Tue, 28 Dec 2020”);
Whenever you make a change to the web site, this variable needs to be changed. It's currently set to
Tue,
28
Dec
2020
, just to make sure you see a What's New image when you refresh the page. A better
alternative for live pages would be the
document.lastModified
property, which returns the date on
which the page was last changed.