Skip to Content

Online and Offline capability in HTML5

Hi,

Here we comes to know how to store data into HTML5 local database. HTML5 introduced Local storage concepts. The Main use for this concept was offline capabilities and local persisted storage features, you can deliver the same rich user experiences online and offline that were previously available only in proprietary desktop application development frameworks. HTML5 localStorage is synchronous and is currently the only database storage mechanism that is supported cross-platform and cross-browser.

How to use?

Step1 :

SetItems to Local DB:

Window.localStorage.setItem(“giveKeyValues”, “YourArrayItems”);

For ex :

Var serNumArr = [];//Create Array put your rec into this array

var notiNumRcvdString =    JSON.stringify(serNumArr);

              window.localStorage.setItem(“NewSerialNumbersMob26”,notiNumRcvdString);

Capture.JPG

 

GetItems from DB:

Window.localStorage.getItem(“giveKeyValues”);




newScanArray = window.localStorage.getItem(“NewSerialNumbersMob26”); // It will return your rec

var getSerNumInArray = new Array();

              getSerNumInArray  = JSON.parse(newScanArray);// Convert your Db rec to Below format

                     Internal function of JSON.parse(newScanArray):

                     getSerNumInArray [0] = 124567

getSerNumInArray [1] = 1245789 …

Remove Items:

  Window.localStorage.removeItems(“giveKeyValues”);

It will remove Items based on your KeyValue

Thanks,

Karthik A

1 Comment
You must be Logged on to comment or reply to a post.
  • Hi Karthik,

    How do the HTML5 offline capabilities relate to those built into SAPUI5?  Can you compare the two and also perhaps suggest when one is to be preferred over the other?

    Regards, Mike

    SAP Customer Experience Group – CEG