When do items in HTML5 local storage expire?

I would suggest to store timestamp in the object you store in the localStorage var object = {value: “value”, timestamp: new Date().getTime()} localStorage.setItem(“key”, JSON.stringify(object)); You can parse the object, get the timestamp and compare with the current Date, and if necessary, update the value of the object. var object = JSON.parse(localStorage.getItem(“key”)), dateString = object.timestamp, now … Read more

How to save an image to localStorage and display it on the next page?

To whoever also needs this problem solved: Firstly, I grab my image with getElementByID, and save the image as a Base64. Then I save the Base64 string as my localStorage value. bannerImage = document.getElementById(‘bannerImg’); imgData = getBase64Image(bannerImage); localStorage.setItem(“imgData”, imgData); Here is the function that converts the image to a Base64 string: function getBase64Image(img) { var … Read more

HTML5 Local storage vs. Session storage

localStorage and sessionStorage both extend Storage. There is no difference between them except for the intended “non-persistence” of sessionStorage. That is, the data stored in localStorage persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site. For sessionStorage, changes are only available per tab. Changes made … Read more

What is the difference between localStorage, sessionStorage, session and cookies?

This is an extremely broad scope question, and a lot of the pros/cons will be contextual to the situation. In all cases, these storage mechanisms will be specific to an individual browser on an individual computer/device. Any requirement to store data on an ongoing basis across sessions will need to involve your application server side … Read more

How do I store an array in localStorage? [duplicate]

localStorage only supports strings. Use JSON.stringify() and JSON.parse(). var names = []; names[0] = prompt(“New member name?”); localStorage.setItem(“names”, JSON.stringify(names)); //… var storedNames = JSON.parse(localStorage.getItem(“names”)); You can also use direct access to set/get item: localstorage.names = JSON.stringify(names); var storedNames = JSON.parse(localStorage.names);

What is the max size of localStorage values?

Quoting from the Wikipedia article on Web Storage: Web storage can be viewed simplistically as an improvement on cookies, providing much greater storage capacity (10 MB per origin in Google Chrome(https://plus.google.com/u/0/+FrancoisBeaufort/posts/S5Q9HqDB8bh), Mozilla Firefox, and Opera; 10 MB per storage area in Internet Explorer) and better programmatic interfaces. And also quoting from a John Resig article … Read more