Does localStorage.clear(); clear ALL from PC?

76 Views Asked by At

If I call the following:

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

Does this clear all local storage from a user machine or just what my site has set?

1

There are 1 best solutions below

0
On BEST ANSWER

From 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.

In the above, "the object" in this context would be localStorage. What is localStorage? From the spec:

The localStorage object provides a Storage object for an origin.

So, it will just clear out the data for your origin, or domain.