0

HTML5 Storage

Posted by Nantharupan on 11:12 PM in ,
HTML5 Storage

HTML5 included two mechanism to store user data in client side. 


  1. session storage
  2. local storage

Session Storage

The session storage is designed for scenarios where the user is carrying out a single transaction, but could be carrying out multiple transaction in different window at the same time.
  • How to store the values
<script type="text/javascript">
sessionStorage.star = 1;
</script>
  • How to retrieve the values
<script type="text/javascript">
document.write("Total star Earned " +sessionStorage.star);
</script>

  • How to clear sessionstorage
    • Session storage will be cleared when browser closed
Local Storage

The Local Storage is designed for storage that spans multiple windows and lasts beyond the current session.
  • How to store the values
<script type="text/javascript">
localStorage.star = 1;
</script>

  • How to retrieve the values
<script type="text/javascript">
document.write("Total star Earned " + localStorage .star);
</script>
  • How to clear localStorage
localstorage.clear(); will clear all local storage;
or
localStorage.remove("key"); will remove particular key
<script type="text/javascript">
localStorage.clear();
</script>

0 Comments

Post a Comment

Popular posts

Copyright © 2009 On the way All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.