How can we not lose Session from one tab to another?

Asked

Viewed 524 times

0

I am trying to create a login in which after validating that the user and password are correct create in sessionStorage the following variable:

sessionStorage.setItem('ClienteId', resp.ClienteId);

By doing so when entering each page I check before if there is the client in Session, but when changing tab I lose the same. I could work without losing her?

Or any better way to log in? Thanks in advance.

2 answers

1


For this you can use the localStorage, where it can be shared between browser tabs.

0

I think using sessionStorage is a good option, since this will not perform the persistence of the data, while localStorage will do it.

That is, if you restart the browser for example, the sessionStorage data will be erased (not persistent), while the data will remain in the localStorage.

There goes your need. I believe in your case, because it is a client ID, the interesting thing is to 'disappear' it when you close the browser, then sessionStorage even.

  • I used Localstorage even performing a Session abandon if you leave the page or ask to reload!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.