HTML5 Storage
HTML5 included two mechanism to store user data in client side.
- session storage
- 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.
<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.
<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>