gpt4 book ai didi

javascript - localStorage.clear();从 PC 清除所有?

转载 作者:可可西里 更新时间:2023-11-01 13:07:20 25 4
gpt4 key购买 nike

如果我调用以下内容:

window.onbeforeunload = function() {
localStorage.clear();
};

这会清除用户机器上的所有本地存储还是只清除我网站设置的内容?

最佳答案

来自 the spec for clear :

The clear() method must atomically cause the list associated with the object to be emptied of all key/value pairs, if there are any. If there are none, then the method must do nothing.

在上文中,此上下文中的“对象”将是 localStorage。什么是 localStorage?来自 the spec :

The localStorage object provides a Storage object for an origin.

因此,它只会清除您的来源或域的数据。

关于javascript - localStorage.clear();从 PC 清除所有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30849915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com