javascript - 有什么方法可以检测用户是否从本地存储中删除了任何项目

标签 javascript reactjs security web

我正在使用reactJS开发一个网络应用程序,并且我正在使用本地存储来存储临时数据,如果从本地存储中删除了任何这些数据,我想将用户注销。

最佳答案

来自MDN

Responding to storage changes with the StorageEvent

The StorageEvent is fired whenever a change is made to the Storage object (note that this event is not fired for sessionStorage changes). This won't work on the same page that is making the changes — it is really a way for other pages on the domain using the storage to sync any changes that are made. Pages on other domains can't access the same storage objects.

在事件页面(see events.js)唯一的 JavaScript 如下:

window.addEventListener('storage', function(e) {  
  .....
});

关于javascript - 有什么方法可以检测用户是否从本地存储中删除了任何项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51265019/

相关文章:

reactjs - NPM 7 工作区安装多个版本的 react

javascript - jquery 连接列表防止掉落在指定的列表上

javascript - 悬停和焦点上的 Twitter Bootstrap 工具提示

javascript - AngularJS 使用 ng-options 创建 Set

css - 为什么 Devextreme 网格溢出了它的父容器,为什么它没有创建垂直滚动条?

javascript - React Highcharts 更改本地状态中选定列的边框颜色

安全道德保密

java - 通过 Web 应用程序访问本地文件

security - 如何从浏览器隐藏 meteor 服务器端代码?

javascript - Jquery Repeater 解析 jquery 中的值