Data storage on client

In HTML5 , data can be stored on the Client side and can be used whenever the website wishes. There are two types of data storage method defined :- localStorage and sessionStorage.

localStorage

It stores the data on client side for any period of time. Initially, it was done by COOKIE variable. However, this method is considered inefficient as COOKIE variables are sent to the server every time a request is made. So, this puts a limit over the amount of data that can be saved in COOKIE. Otherwise, it will be make the website very slow. However, in HTML5 only required values are sent to the server. These data can be accessed by Javascript. Thus, we selectively find out what we require using javascript and then selectively send the data to the server.To save a variable to localStorage :-


localStorage.value1 = "First local storage value"; // string saved
document.write(localStorage.value1); // prints First local storage value

We can use it to check how many times you have visited a page



if (localStorage.pagecount)
  {
  localStorage.pagecount=Number(localStorage.pagecount) +1;
  }
else
  {
  localStorage.pagecount=1;
  }
document.write("
You visited the page "+ localStorage.pagecount + " time(s).
");

These values are set at different arears for different websites and a website can only use data stored by itself.

sessionStorage

sessionStorage are used to store a value to the clients machine only till the session expires. It is also accessible from javascript and is totally similar to localStorage except the expiry time.


sessionStorage.value1="Session Value";
document.write(sessionStorage.value1);

Lets deal with newly introduced HTML5 form input types now :-

Member Login

Member Login




Not a Member? Sign Up!




Login to comment

Be the first to comment on this topic







  


<<< Wanna review

Continue >>>