Get Website Learn Coding Tech Story

HTML5 Examples

Html5 web storage is more secure and faster mechanisms, similar to HTTP session cookies, for storing structured data on the client browser. It is also possible to store large amounts of data, without affecting the website's performance.

There are two new objects for storing data on the client. Local Storage which is used to stores data with no expiration date and Session Storage which is used to stores data for one session

Local Storage

The Local Storage is designed for storage the data without expiration date. The data will not be deleted when the browser is closed even can be use by and lasts beyond the current session. In particular, Web applications may wish to store megabytes of user data, such as entire user-authored documents or a user's mailbox, on the client side for performance reasons.

Session Storage

The Session Storage used to store multiple transactions in different windows at the same time.

/* Local Storage example */
<script type="text/javascript">
	if(localStorage.hits )
		localStorage.hits = Number(localStorage.hits) +1;
	else
		localStorage.hits = 1;

	document.getElementById("hitcount").innerHTML="Total Hits :" + localStorage.hits;
</script>

<div id="hitcount"></div>


/* Session Storage example */ 
<script type="text/javascript">
	if(sessionStorage.hits) 
		sessionStorage.hits = Number(sessionStorage.hits) +1;
	else
		sessionStorage.hits = 1;
	document.getElementById("hitcount").innerHTML="Total Hits :" + sessionStorage.hits;
</script>

<div id="hitcount"></div>