Java Reference
In-Depth Information
the first page only if the user has visited the page before (that is, if a cookie exists) but has not visited
since the page was last updated.
Let's create the first page:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 13: Example 2a</title>
</head>
<body>
<h1>Welcome to Example 2a</h1>
<div id="whatsNew"></div>
<script src="cookiefunctions.js"></script>
<script>
var lastUpdated = new Date("Tue, 28 Dec 2020");
var lastVisit = getCookieValue("LastVisit");
if (lastVisit) {
lastVisit = new Date(lastVisit);
if (lastVisit < lastUpdated) {
document.getElementById("whatsNew").innerHTML =
"<a href='ch13_example2b.html'>What's New?</a>";
}
}
var now = new Date();
setCookie("LastVisit", now.toUTCString());
</script>
</body>
</html>
Save this page as ch13 _ example2a.html . Note that it uses the two functions, setCookie() and
getCookieValue() , that you created earlier.
Next, you just create a simple page to link to for the What's New? details:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 13: Example 2b</title>
</head>
<body>
<h1>Welcome to Example 2b</h1>
<h3>Here's what's new!</h3>
</body>
</html>
Save this page as ch13 _ example2b.html .
Search WWH ::




Custom Search