HTML5 Web Storage

Storing Data on the Client


Storing information on the shopper
HTML5 offers 2 new objects for storing information on the client:

    localStorage - stores information with no limit
    sessionStorage - stores information for one session

Earlier, this was done with cookies. Cookies aren't appropriate for giant amounts of information, as a result of they're passed on by each request to the server, creating it terribly slow and in-effective.
In HTML5, the information isn't passed on by each server request, however used solely when asked for. it's potential to store massive amounts of information while not affecting the website's performance.
The data is stored in numerous areas for various websites, and a web site will solely access information stored by itself.
HTML5 uses JavaScript to store and access the information.

The localStorage Object
The localStorage object stores the information with no limit. the information are out there successive day, week, or year.
How to produce and access a localStorage:

Example

<script type="text/javascript">
localStorage.lastname="Smith";
document.write(localStorage.lastname);
</script> 
The following example counts the number of times a user has visited a page:

Example

<script type="text/javascript">
if (localStorage.pagecount)
  {
  localStorage.pagecount=Number(localStorage.pagecount) +1;
  }
else
  {
  localStorage.pagecount=1;
  }
document.write("Visits "+ localStorage.pagecount + " time(s).");
</script>

The sessionStorage Object
The sessionStorage object stores the information for one session. the information is deleted when the user closes the browser window.
How to produce and access a sessionStorage:

Example

<script type="text/javascript">
sessionStorage.lastname="Smith";
document.write(sessionStorage.lastname);
</script> 

The following example counts the quantity of times a user has visited a page, within the current session:

Example

<script type="text/javascript">
if (sessionStorage.pagecount)
  {
  sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
  }
else
  {
  sessionStorage.pagecount=1;
  }
document.write("Visits "+sessionStorage.pagecount+" time(s) this session.");
</script>


Partner site : online news

0 comments: