简体   繁体   English

浏览器重启后清除本地存储变量

[英]clear local storage variable after browser restart

I have the following variable localStorage.timesDisplayed in the browser's local storage.我在浏览器的本地存储中有以下变量localStorage.timesDisplayed

I am wondering if there is a way to clear that variable with Javascript when browser is restarted.我想知道是否有办法在浏览器重新启动时使用 Javascript 清除该变量。

I can use : delete localStorage.timesDisplayed to delete the variable, but I am not sure how to detect that the browser has been restarted on the page load.我可以使用: delete localStorage.timesDisplayed来删除变量,但我不确定如何检测浏览器是否在页面加载时重新启动。

You could use sessionStorage instead.您可以改用 sessionStorage。 It will clear when the user exits your site.它会在用户退出您的网站时清除。

https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

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

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