Thursday, August 11, 2011

How to use HTML5 local store?

I have prepared a small example which show how to use HTML local storage feature. The concept is similar to cookies, but it’s designed for larger quantities of information. Cookies are limited in size, and your browser sends them back to the web server every time it requests a new page which takes extra time and precious bandwidth.

<!DOCTYPE html>

function putInLocalStore(){
    localStorage.setItem("comments", document.getElementById("comments").value);

function getFromLocalStore() {
    var data = localStorage.getItem("comments");
    var comments = document.getElementById("comments");
    comments.value = (data != "") ? data : "";

function pageOnLoad(){

    <body onLoad="pageOnLoad();">
        Enter data to put in local store: <input id="comments" type="text" >
        <input id="submit" type="button" value="Store" onclick="putInLocalStore();" />

Chrome browser supports most of the HTML5 features. Copy the sample and execute it on latest chrome browser.

No comments:

Post a Comment

Example code to connect node.js REST service with Eureka discovery service

Eureka is Spring based discovery service developed by Netflix. To know how Eureka is used at Netflix visit: