1

I am storing some data in the local storage using

localstorage.setItem("key","value")

I understand that localstorage is browser specific, now will this value remain even after i login as different user (sharepoint) in the same browser?

as far as i know localStorage is persistent until user clears it

and i read in this SO question that

Duration

In DOM Storage it is not possible to specify an expiration period for any of your data. All expiration rules are left up to the user. In the case of Mozilla, most of those rules are inherited from the Cookie-related expiration rules. Because of this you can probably expect most of your DOM Storage data to last at least for a meaningful amount of time.

So does this mean that local storage is only browser specific? ie even if login as different user in sharepoint, the localstorage values will still remain if i use the same browser? (given that i dont clear it in log out/log in actions in sharepoint)

Community
  • 1
  • 1
Vignesh Subramanian
  • 6,513
  • 8
  • 67
  • 131

2 Answers2

1

I understand that localstorage is browser specific, now will this value remain even after i login as different user in the same browser?

Yes. Definitely.

It has nothing to do with php sessions or the like. Nothing. LocalStorage is attached to the browser. Log in or log out, has no effect on localStorage.

even if login as different user, the localstorage values will still remain if i use the same browser?

Yes.

Marcel Burkhard
  • 3,212
  • 1
  • 28
  • 31
3pic
  • 1,172
  • 8
  • 26
  • 1
    In most cases, clear storage after sign out https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear – AJcodez Jul 23 '15 at 13:33
  • If your question is 'how to clear localStorage', AJCodez points the right link: developer.mozilla.org/en-US/docs/Web/API/Storage/clear – 3pic Jul 23 '15 at 14:05
1

You can wrap browser storage with your own interface. It can have expiration by setting a timestamp on writes and checking it on reads.

var Storage = {
  get: function (key) {
    var item = localStorage.getItem(key)
    if (item) {
      var entry = JSON.parse(item)
      if (entry.expires && Date.now() > entry.expires) {
        localStorage.removeItem(key)
      } else {
        return entry.data
      }
    }
  },

  set: function (key, value, expires) {
    var entry = { data: value }
    if (expires) { entry.expires = expires }
    var item = JSON.stringify(entry) 
    localStorage.setItem(key, item)
  },
}
AJcodez
  • 26,232
  • 17
  • 72
  • 110