简体   繁体   English

使用HTML和JavaScript在本地存储数据

[英]Store data locally using HTML and JavaScript

I have a small LAN with some computers. 我有一台带有一些电脑的小型局域网。

I'm looking for a way to build a dynamic HTML webpage that uses JavaScript to store some data locally (can't use server side - only client side). 我正在寻找一种方法来构建一个动态HTML网页,该网页使用JavaScript在本地存储一些数据(不能使用服务器端 - 仅客户端)。

The webpage will be stored on a network drive shared with all the computers. 该网页将存储在与所有计算机共享的网络驱动器上。

I wish to do that using a file, maybe an XML file or something similar that will be loaded using JavaScript and then saved again after some changes. 我希望使用一个文件,可能是一个XML文件或类似的东西,使用JavaScript加载,然后在一些更改后再次保存。

The data must be shared with all the computers on the LAN. 必须与LAN上的所有计算机共享数据。

How can I do this? 我怎样才能做到这一点?

HTML5 localStorage 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. 1. LocalStorage :您可以将数据存储在变量中。 There would be a limit as to how much data you can store. 您可以存储多少数据是有限制的。

Refer : http://en.wikipedia.org/wiki/Web_storage . 请参阅: 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. 2. WebSQL :这应该是在客户端存储的最简单方法。 WebSQL is supported in almost all current browsers(HTML5). 几乎所有当前浏览器(HTML5)都支持WebSQL。 However there is no longer official support for WebSQL as its depreciated and no future updates. 但是,由于WebSQL的折旧和未来更新,因此不再对WebSQL提供官方支持。

Refer : http://en.wikipedia.org/wiki/Web_SQL_Database 请参阅: http//en.wikipedia.org/wiki/Web_SQL_Database

3. IndexedDB : This is also another way to store data in local database. 3. IndexedDB :这也是在本地数据库中存储数据的另一种方法。 However this is not yet supported in all browsers. 但是,并非所有浏览器都支持此功能。

4. XML 4. XML

If you are going forward with storing data in local DB, then you can utilize PersistenceJS . 如果您正在将数据存储在本地数据库中,那么您可以使用PersistenceJS

Refer : https://github.com/zefhemel/persistencejs 请参阅: https//github.com/zefhemel/persistencejs

您可以使用HTML 5 LocalStorage

根据您存储的数据的风​​格,简单的cookie可能会工作,使用普通的JS访问。

finally I found a solution for it! 最后我找到了解决方案! I am using a jQuery plugin called: twFile ( http://jquery.tiddlywiki.org/twFile.html ). 我正在使用一个名为:twFile( http://jquery.tiddlywiki.org/twFile.html )的jQuery插件。 It uses an activeX FileSystemObject - it works great on IE9. 它使用activeX FileSystemObject - 它在IE9上运行良好。

Try like this: 试试这样:

store a value : 存储一个值:

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

get a value: 得到一个值:

localStorage.getItem("lastname");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM