Local Storage (html5)

14 / Dec / 2010 by Umar 0 comments

HTML5 storage provides a way for websites to store information on your computer and retrieve it later. The concept is similar to cookies, but cookies do not store larger quantities of data. Cookies are limited in size, and your browser sends a request to the web server every time a new request is initiated (which takes extra time and bandwidth). HTML5 storage stays on your computer, and websites can access it with JavaScript after the page is loaded.

Detection browser technique –

     function supports_local_storage() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch(e){
    return false;
  }
}

If your browser supports HTML5 storage, there will be a localStorage property on the global window object. If your browser doesn’t support HTML5 storage, the localStorage property will be undefined. Add this modernizr.js file and use this function:

if (Modernizr.localstorage) {
  // window.localStorage is available!
} else {

  // maybe try Gears or another third-party solution
}

Note that JavaScript is case-sensitive. The Modernizr attribute is called localstorage (all lowercase), but the DOM property is called window.localStorage

FOUND THIS USEFUL? SHARE IT

Leave a comment -