Java Reference
In-Depth Information
What's New? Now with Local Storage
trY it out
Let's rewrite Example 2 using local storage. Feel free to copy and paste the contents of
ch13 _ example2a.html and ch13 _ example2b.html as the basis for the new files.
Let's create the first page:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 13: Example 3a</title>
</head>
<body>
<h1>Welcome to Example 3a</h1>
<div id="whatsNew"></div>
<script>
var lastUpdated = new Date("Tue, 28 Dec 2020");
var lastVisit = localStorage.lastVisit;
if (lastVisit) {
lastVisit = new Date(lastVisit);
if (lastVisit < lastUpdated) {
document.getElementById("whatsNew").innerHTML =
"<a href='ch13_example3b.html'>What's New?</a>";
}
}
localStorage.lastVisit = new Date();
</script>
</body>
</html>
Save this page as ch13 _ example3a.html . Next, create a simple page to link to for the What's New?
details:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 13: Example 3b</title>
</head>
<body>
<h1>Welcome to Example 3b</h1>
<h3>Here's what's new!</h3>
</body>
</html>
Save this page as ch13 _ example3b.html .
Search WWH ::




Custom Search