Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localstorage not sharing data between tabs #252

Closed
ashiefk opened this issue Sep 2, 2015 · 3 comments
Closed

localstorage not sharing data between tabs #252

ashiefk opened this issue Sep 2, 2015 · 3 comments

Comments

@ashiefk
Copy link

ashiefk commented Sep 2, 2015

I have implemented localstorage in my web app configuration given below,

app.config(function (localStorageServiceProvider) {
localStorageServiceProvider
.setPrefix('appName')
.setStorageType('sessionStorage')
.setNotify(true, true)
});

and i set some data inside localstorage but when i checked in different tab (browser tabs) its returning null. Is there anything which i missed in configuration (do i need to change sessionStorage to cookie?). Is there anything i need to specify inorder to share the data between tabs? Please help !!! I really need the data between tabs just like server session.

@juliendangers
Copy link

you can't share data between multiple tabs using sessionStorage, because a new page is a new session

see MDN

Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.

You need to replace
. setStorageType('sessionStorage')
by
. setStorageType('localStorage') // which is default

@ashiefk
Copy link
Author

ashiefk commented Sep 2, 2015

Thank you so much, really helpful info.

@ashiefk ashiefk closed this as completed Sep 2, 2015
@aplocher
Copy link

Is there a way to get the best of both worlds? When the browser is closed the session no longer exists (as is the case with "sessionStorage") but while actively using the browser the user will stay logged in across tabs?

Correct me if I'm wrong, but I think this is the type of behavior you would see using something like PHP to manage the sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants