javascript – 如果取消对localStorage的写入会怎样?

假设我打电话给本地存储,如下所示:

window.localStorage.setItem("key", bigJsonObject);

然后,用户立即关闭其Web浏览器.结果会是什么?

window.localStorage.getItem("key") 

bigJsonObject会被部分写入吗?或者整个写入会失败吗?他们有什么方法可以保证不会有部分写入?

解决方法:

参见§4.1 of the “web storage” specification

The setItem() and removeItem() methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all.

但是,(历史上)在这方面存在浏览器错误,e.g. some time before Chrome 21 until some time before Chrome 29.

相关文章

公司前端界面用的是vue,我要嵌入到Android中生成App第一步:...
Q:我用cordova开发项目,想在app内跳转外部链接,安装了cord...
我正在使用https://github.com/arnesson/cordova-plugin-fir...
一、Cordova的基础点在混合式应用中,我们通过现有的Cordova...
cordova自定义插件注意:存放自定义cordova插件目录不能有空...
一、问题VueAPP中有一个文件下载功能,用了各种方法来实现下...