HTML5 Local Storage

An other cool feature in the new HTML5 is the Local Storage.

You can save date without any database or files.

With a simple JavaScript function you can edit just using the broswer. You can refresh and even restart the brower and the information will be there 😉

View Demo

html5-local-storage-demo

Test Local Storage

For some browsers (Safari private mode on Mac and iOS) it might fail if you just try to set the localStorage directly.

First you have to test it:


function testLocalStorage() {
try {
localStorage.setItem(storageName, storageName);
localStorage.removeItem(storageName);
return true;
} catch(e) {
return false;
}
}

if( testLocalStorage() ){
localStorage.setItem('Your-Item-Name', true);
}

Demo Code


Checkout the W3 oficial Web Storage documentantion.

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*