ekuemoah Posted February 7, 2011 Share Posted February 7, 2011 Hello,I used the localStorage command to store a cookie and retrieve a cookie. I noticed that I was able to retrieve the stored value when I stored the cookie and then pressed retrieve button. However, I was not able to do this when I stored it, closed the browser, and then tried to retrieve it. It acted like a session cookie or a temporary cookie was stored instead of a persistent cookie. How do I make the cookie into a permanent or persistent cookie?Thanksfunction storeMyName(){var fname =document.getElementById('fname').value;alert(fname);localStorage.setItem('firstname',fname);alert("Name Stored");}function getMyName(){ alert(localStorage.getItem('firstname')); } Link to comment Share on other sites More sharing options...
boen_robot Posted February 7, 2011 Share Posted February 7, 2011 Let me first try to give you some medicine for the marketing hype acid you've been drinking...HTML5 is both a buzzword and an actual specification (that's where it's unique to previous hypes)...HTML5 - the spec - defines a few new elements and attributes for the sake of semantics. They don't really "do" much, with a few motable exceptions like the "video" and "audio" elements which have the ambition of complementing "img", and the new values for the "type" attribute of the "input" element. It's major goal is not those elements however, but to standardize how browsers handle non well formed HTML.HTML5 - the buzzword - is an umbrella term for every fancy new unifinished thing browsers are implementing such as the HTML5 spec itself, various CSS3 modules, SVG, JavaScript APIs (such as localStorage, geoLocation, Web Workers and many more), etc.Many developers, myself included, frown upon the use of buzzwords as if they're technical terms. In technical discussions, HTML5 should always refer to HTML5 - the spec.Also, localStorage is not the same as cookies. It's similar in that it provides a way for you to store data per computer/browser, but it's different in that this information is only available to the JavaScript of that computer/browser and has a much greather capacity.OK... enough medicine... for your issue... could you show us the full code? It sounds like there's a third function there that's clearing the storage (probably in an onunload event handler).<< Moved to the JavaScript forum; reasoning above >> Link to comment Share on other sites More sharing options...
ekuemoah Posted February 7, 2011 Author Share Posted February 7, 2011 Can I still use HTML or Javascript cookies in my program alongside with the WebStorage methods. If use cookies and the DOCTYPE is set to HTML 5, will I get an error in my program or will my cookie program functions not work any more?Here's my code: function storeMyName(){var fname =document.getElementById('fname').value;alert(fname);localStorage.setItem('firstname',fname);alert("Name Stored");}function getMyName(){ alert(localStorage.getItem('firstname')); } Let me first try to give you some medicine for the marketing hype acid you've been drinking...HTML5 is both a buzzword and an actual specification (that's where it's unique to previous hypes)...HTML5 - the spec - defines a few new elements and attributes for the sake of semantics. They don't really "do" much, with a few motable exceptions like the "video" and "audio" elements which have the ambition of complementing "img", and the new values for the "type" attribute of the "input" element. It's major goal is not those elements however, but to standardize how browsers handle non well formed HTML.HTML5 - the buzzword - is an umbrella term for every fancy new unifinished thing browsers are implementing such as the HTML5 spec itself, various CSS3 modules, SVG, JavaScript APIs (such as localStorage, geoLocation, Web Workers and many more), etc.Many developers, myself included, frown upon the use of buzzwords as if they're technical terms. In technical discussions, HTML5 should always refer to HTML5 - the spec.Also, localStorage is not the same as cookies. It's similar in that it provides a way for you to store data per computer/browser, but it's different in that this information is only available to the JavaScript of that computer/browser and has a much greather capacity.OK... enough medicine... for your issue... could you show us the full code? It sounds like there's a third function there that's clearing the storage (probably in an onunload event handler).<< Moved to the JavaScript forum; reasoning above >> Link to comment Share on other sites More sharing options...
jeffman Posted February 7, 2011 Share Posted February 7, 2011 Cookies are here to stay, and the new doctype doesn't change that. There should be no trouble. Link to comment Share on other sites More sharing options...
boen_robot Posted February 8, 2011 Share Posted February 8, 2011 Cookies and WebStorage are two separate things, not dependant on each other.WebStorage in dependant on JavaScript... it can be used in any environment that has JavaScript and supports this API (e.g. IE8+, Firefox 3.5, etc.).Cookies are not specific to JavaScript or HTML... they're specific to the HTTP protocol. They can be used by any user agent that supports HTTP and cookies (e.g. all browsers).What you're showing us is not your full code. That's only part of your code. Show us everything from the DOCTYPE to the "</html>". Link to comment Share on other sites More sharing options...
Wolverine Posted December 11, 2011 Share Posted December 11, 2011 I have a question on localstorage as well. When I copy it to Dreamweaver so that from the w3schools.com tutorial so that I have an idea what it is I get the message: there is an error on line5. Code hinting may not work until you fix this error. Here is the code that gives this message: <script type="text/javascript">if (localStorage.pagecount){localStorage.pagecount=Number(localStorage.pagecount) +1;}else{localStorage.pagecount=1;}document.write("Visits: " + localStorage.pagecount + " time(s).");</script> line 5 is the one that says: localStorage.pagecount=Number(localStorage.pagecount) +1; I do not know enough from just a few days of reading the online tutorial to figure out what the error is. Link to comment Share on other sites More sharing options...
JamesB Posted December 11, 2011 Share Posted December 11, 2011 hmm i can't see any errors with that code, when you actually visit the page in a browser do any javascript errors show up in the error console? i remember a mate showing me dreamweaver saying "?:" wasn't valid in PHP too, lol. Notepad++ Link to comment Share on other sites More sharing options...
Wolverine Posted December 12, 2011 Share Posted December 12, 2011 When I look on the error console just now I find an interesting warning:Warning: Use of getAttributeNode() is deprecated. Use getAttribute() instead.Source File: http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_webstorage_local_pagecountLine: 0Not sure just what it means but that I need to ask what it means. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 12, 2011 Share Posted December 12, 2011 Deprecated means that it has been replaced with something else and shouldn't be used any more. Link to comment Share on other sites More sharing options...
Wolverine Posted December 13, 2011 Share Posted December 13, 2011 Thanks it answers my question. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.