问题标签 [web-storage]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2735 浏览

javascript - jQuery:在输入字段上使用网络存储/本地存储

我正在尝试保存/检索表单中所有输入字段的值。不幸的是,这不起作用。
令人沮丧的是,我不知道出了什么问题。我已经测试了类型:键和值都是字符串。事件被正确附加,console.log被触发。
你在这段代码中看到了什么让你印象深刻的东西吗?为什么没有保存或检索任何值?

当然,我在支持网络存储的浏览器中进行测试,并且每个输入都有一个 id。

0 投票
1 回答
2112 浏览

local-storage - IE10 中 localStorage 和 sessionStorage 的替代方案

我知道localStorage并且sessionStorage在 IE10 中不允许本地文件(即)file:///协议。但是在本地存储数据并为本地文件检索它们的替代方法是什么?有没有其他可用的方法或插件?

0 投票
2 回答
3070 浏览

javascript - 尝试使用会话存储,得到“无法设置未定义或空引用的属性‘登录’

因此,我正在尝试为一个基本的 javascript 类编写一个简单的代码,该类将为用户维护一个登录状态。他们登录的功能如下

我只是在用户名和登录中进行硬编码,因为我还没有任何数据库经验,仅用于测试目的。我正在和我的老师谈论这件事,给他发送了我的整个网站的电子邮件,他说它对他来说工作得很好,所以为什么它在我的机器上不起作用,它给了我这个 Unable to set property error on粗线...

我在 Windows 8 上运行 IE 10.0.11,并运行了一个检查会话存储兼容性的脚本,结果它恢复正常......所以......理论上它应该可以工作吗?到底是什么问题?

0 投票
1 回答
492 浏览

javascript - 将 WebSQL 与 async.js 一起使用,导致 InvalidStateError

我正在尝试将 WebSQL API 与 async.js 一起使用以使其更易于使用。我使用该方法async.waterfall()将事务对象从一个函数传递到另一个函数。这是一个简单的例子:

当我调用tx.executeSql()Chrome 的控制台时说:Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
这很可能是指tx对象。

使用传统方式(创建“功能瀑布”)的 WebSQL 可以正常工作。以这样的方式使用 WebSQL 有什么需要注意的吗?还是有更好的选择?

0 投票
1 回答
96 浏览

javascript - 无法使用 HTML5 Web Storage 保存布尔值的解决方法

我目前正在使用 Javascript 或更准确地说是 CraftyJS 制作马里奥风格的游戏。

我已将此处作为参考,并了解如何保存用户输入的值。但我想要完成的是自动保存某些布尔值(它们被称为什么?),或者当玩家按下保存按钮或其他东西时。

例如,我有一个名为 dungeon1 的地下城,我创建了一个变量来表示地下城是否已完成。

var dungeon1 = false;默认情况下。

但是当玩家完成 dungeon1 时,它会变为var dungeon1 = true;,从而在世界地图中添加新内容,例如通往 dungeon2 的门户(这工作正常)。

我要保存的是这条var dungeon1 = true;语句,这样当用户再次打开游戏时,完成的地牢就会被加载并正确显示相应的解锁。我该怎么做?有没有办法说,制作一个名为 的保存管理文件save.js,然后在它们变为 时存储上述布尔值true

0 投票
2 回答
309 浏览

javascript - 如何将 jQuery 克隆文本输入保存到 cookie 或 html5 存储?

我有一个文本输入,当用户单击按钮时,jQuery 克隆输入并制作另一个。

现在,我的问题是 - 我如何将输入表单保存到 cookie 或 html5 存储中(什么是更好的解决方案?)。我希望页面刷新何时出现克隆的文本输入,这些文本输入之前使用 cookie 或 html5 保存。谢谢!

0 投票
3 回答
1230 浏览

javascript - 拦截 localStorage.getItem()

有没有办法拦截对 localStorage 的调用?或者可能存在一些处理程序?

如果我在 localStorage.getItem() 之类的代码脚本中有某个地方,我需要知道存储将获取一些项目,并且我想防止这种情况发生,并做一些我需要的事情。

我想为移动 Web 开发人员编写一个框架。我希望他们以通常的方式使用本地存储调用。我的框架将拦截此调用,并将数据不放入 W3C 存储,而是放入本机设备存储。那可能吗?谢谢。

0 投票
1 回答
482 浏览

local-storage - 来自 LocalStorage 的 Geb getItem

我用geb测试我的网络应用程序。

如何使用 GEB 从站点 localStorage 获取项目?

有什么帮助吗?

我看这个答案,但它对我不起作用。

0 投票
1 回答
371 浏览

angularjs - 如何将“缓存依赖”设置为本地存储

我们正在使用来自 angularjs 的本地存储模块。

https://github.com/grevory/angular-local-storage

现在任何人都可以建议我们如何在客户端设置缓存依赖项,以便当服务器中的数据更改时本地存储无效(强制从服务器重新获取数据)。

现在在测试环境中,每次发布时我们都必须要求测试人员清除浏览器缓存。不能在生产中使用这种方法。

感谢您的帮助。

0 投票
3 回答
2095 浏览

javascript - Web Storage for website localization

I am trying to create a website that shows the selected language page at first visit. On click of the language name, the language name string (eg. French) gets stored in the web/local storage. And when the next time user visits the website, the language string is checked and specific language page is shown. I have written twelve functions for storing the language string on click of anchor tag of each language. Like this:

Is this method really efficient? I think creating multiple pages for multiple language is good for SEO rather than changing the text string on the fly. Till here when I check the Chrome developers console, the value of the string gets stored. But when I close the tab or the browser window the stored value is gone and the next time it cannot remember the language.

I am checking the language using this code (I have to do it for 12 languages):

The code kinda stops after checking the first 'if' condition, true or false it just stops there and doesn't check the 'else if' condition beyond that.

Can someone please help me this?? The sample codes seems to store the value in web storage even after browser close but I cannot replicate it in mine.