Reputation: 16742
If a website stores a value in local storage for a user on a machine, then later another user signs onto that machine and browses to the site, will the site see and overwrite the first user's value, or will local storage be empty because it's a different user?
(This is a similar question, but no one ever answers the first part: How to deal with localStorage for multiple users?)
Upvotes: 18
Views: 11916
Reputation: 2521
To clarify: the OP is asking what happens with localStorage
when two user profiles access the same site. The quick answer: they do not collide.
localStorage
is stored separately for each browser user profile, just like cookies, passwords, stored form data, etc. If two people log into different accounts on a shared computer and both visit the same site, each person's localStorage
data will be stored in a separate place.
However, this should not be used to store sensitive data! Also, when a user logs out the localStorage
will still be there.
Here is a jsfiddle.
Upvotes: 17
Reputation: 133360
LocalStorage is a simple key-value store, in which the keys and values are strings. There is only one store per domain. This functionality is exposed through the globally available localStorage object. The same applies to sessionStorage.
There aren't user storage component provided by the localStorage system, but if you need you can manage in your html page using javascript
<script>
// Using localStorage
// store data
localStorage.lastName = "LastName";
localStorage.firstName = "FirstName";
localStorage.location = "Location";
// retrieve data
var lastName = localStorage.lastName;
var firstName = localStorage.firstName;
var location = localStorage.location;
</scipt>
this w3c resource and this from html5rocks could be useful
Upvotes: 3