Store data locally using HTML and JavaScript

て烟熏妆下的殇ゞ 提交于 2019-12-01 15:53:19

HTML5 localStorage

//Set
localStorage.setItem("lastname", "Smith");

//Get
var 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:

// Store
localStorage.setItem("sample", "test");
// Retrieve
var 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

You can use HTML 5 LocalStorage

Depending on the flavor of data you're storing, simple cookies might work, accessed with plain old JS.

finally I found a solution for it! I am using a jQuery plugin called: twFile (http://jquery.tiddlywiki.org/twFile.html). It uses an activeX FileSystemObject - it works great on IE9.

Try like this:

store a value :

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

get a value:

localStorage.getItem("lastname");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!