Saturday, March 17, 2012

HTML 5 localStorage usefull methods


With HTML5, web pages can store data locally within the user's browser.

Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website's performance.

The data is stored in key/value pairs, and a web page can only access data stored by itself.

Here I write some usefull method of localStorage.

localStorage.setItem('name','naresh');
This method use for create new items if not exist in localstorage otherwise it overwrite value of item 'name'.

localStorage.getItem('name');
This method give the value of item 'name' of locaStorage.

localStorage.removeItem('name');
This method for remove single and perticuler item from localStorage.

localStorage.clear();
This mehtod use for copmletely clear your localStorage.