I tried to test this code, and this does not seem to work at all for me.. note there was some portion of the code on cookies, that was working fine (hence I deleted that part), and my concern is about localStorage -- when I open a new tab, or reload the page, the localstorage is reset -- why does that happen?? I think it should be something with the code, but I cannot figure it out..
thanks, murali.
- Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Page 1 Cookie </title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
function localStore() {
localStorage.setItem("myLocalData", $("#localdata").val());
}
function sessionStore() {
sessionStorage.setItem("mySessionData", $("#sessiondata").val());
}
</script>
</head>
<body >
<h2> This is Page 1 </h2>
<p id="displayLastVisit"></p>
<p> <a href="page2.html"> Page 2 </a> </p>
<p>
<textarea id="localdata" ></textarea>
</p>
<p><button onclick="localStore()" > Click for local Storage </button></p>
<p>
<textarea id="sessiondata" ></textarea>
</p>
<p><button onclick="sessionStore()" > Click for Session Storage </button></p>
</body>
</html>