HTML and CSS Reference
In-Depth Information
Code
Explanation
try {
Set up
try
clause
olddate = new Date();
Define new
Date
localStorage.setItem("lastdate",olddate);
Store in local storage using the
key
"lastdate"
alert("Stored: "+olddate);
Display message to show what
was stored
}
Close
try
clause
Catch(e) {
Start
catch
clause: if there was a
problem
alert("Error with use of local storage:
"+e);}
Display message
Close
try
clause
}
Return false;
Return
false
to prevent any
page refresh
}
Close function
function remove() {
Remove function header
if (typeof(localStorage) == "undefined")
{
Check if
localStorage
recognized
alert("Browser does not recognize HTML
local storage.");
Display
alert
message
Close
if
clause
}
else {
Else
localStorage.removeItem('lastdate');
Remove the item stored using the
key
'lastdate'
.
alert("Removed date stored.");
Display message indicating what
was done