Store data locally using HTML and JavaScript Store data locally using HTML and JavaScript database database

Store data locally using HTML and JavaScript


HTML5 localStorage

//SetlocalStorage.setItem("lastname", "Smith");//Getvar lastName = localStorage.getItem("lastname");


You have the following options :

1.LocalStorage : You can store data in variables. There would be a limit as to how much data you can store.

Refer : http://en.wikipedia.org/wiki/Web_storage.

Eg:

// StorelocalStorage.setItem("sample", "test");// Retrievevar sample = localStorage.getItem("sample");

2.WebSQL : This should be the most easy way of storing in client side. WebSQL is supported in almost all current browsers(HTML5). However there is no longer official support for WebSQL as its depreciated and no future updates.

Refer : http://en.wikipedia.org/wiki/Web_SQL_Database

3.IndexedDB : This is also another way to store data in local database. However this is not yet supported in all browsers.

4.XML

If you are going forward with storing data in local DB, then you can utilize PersistenceJS.

Refer : https://github.com/zefhemel/persistencejs


Try like this:

store a value :

localStorage.setItem("lastname", "amir");

get a value:

localStorage.getItem("lastname");