StudioTime
StudioTime

Reputation: 23959

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

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?

Upvotes: 3

Views: 60

Answers (1)

James Thorpe
James Thorpe

Reputation: 32192

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.

Upvotes: 3

Related Questions