Using localStorage Cross-Browser
Using localStorage Cross-Browser
Another great new HTML5 feature is the so called local storage. The local storage can be used to quickly store specific information on the users local machine (inside the browser of course) without needing to rely on a cookies.
A quick glance at caniuse.com tells us that nearly every browser already supports this feature. Event IE 8 has it implemented. You can save and load from the local storage like this:
// add a timestamp to the local storage
localStorage.setItem('timestamp', (new Date()).getTime());
// read timestamp from local storage
var timestamp = localStorage.getItem('timestamp');
But what if you absolute need to support older browsers like Internet Explorer 7? Luckily there is a very nice JavaScript Polyfill you can use: jStorage.
The nice thing about jStorage is that it will simply fall back on the local storage if it is available and will only fill in if the user is using a very old browser.
Photo by Travis Wise