Thursday, December 9, 2010

HTML5 client local storage

Most talked feature of html5 is storing data on client side. This could be achieved in 3 ways.
  1. Session storage.
  2. Local storage
  3. Database storage
Session storage: This is more like a upgraded version of a cookie. It persists only during browsing and once window is closed data is lost. This is easy to implement.
sessionStorage.setItem('shoppingId', '23234')
alert("Shopping Id is: " + sessionStorage.getItem('shoppingId'));
//same thing could also be achieved with sessionStorage.shoppingId

//to remove
sessionStorage.removeItem('shoppingId');