These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:04 pm Advanced search

A question about HTML5 storage.

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

A question about HTML5 storage.

Postby mmurali » Mon Apr 22, 2013 6:44 pm

hi everyone,

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>

mmurali
<h6>
 
Posts: 1
Joined: Mon Apr 22, 2013 6:38 pm

Re: A question about HTML5 storage.

Postby JAB Creations » Tue Apr 23, 2013 6:26 pm

The first mistake is that you're not coding with JavaScript, you're using jQuery. As such I can't nor would attempt to answer that. Stick with real code and you'll go a lot further, stuck with frameworks and you'll negatively weigh down all your work and end up wasting more of your time in the long term.

Second you can not use an external script and have scripting on the page directly in a single script element...

Code: Select all
<head>
<script src="scripts/index.js" type="application/javascript></script>
<script type="application/javascript>
//<![CDATA[
/* your code here */
//]]>
</script>
</head>


At least you kept your script elements as children of the head so that will force you to keep your code a higher quality but it will only matter if you learn real JavaScript and not introduce unnecessary dependencies such as jQuery.
User avatar
JAB Creations
<aside>
 
Posts: 566
Joined: Tue Mar 13, 2007 4:48 am
Location: Sarasota Florida, USA


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest