Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular window.localStorage different subdomain [duplicate]

I'm replacing cookies with localStorage on browsers that can support it (anyone but IE). The problem is site.example and www.site.example store their own separate localStorage objects. I believe www is considered a subdomain (a stupid decision if you ask me). If a user was originally on site.example and decides to type in www.site.example on her next visit, all her personal data will be inaccessible. How do I get all my "subdomains" to share the same localStorage as the main domain?

like image 524
JoJo Avatar asked Nov 20 '22 21:11

JoJo


1 Answers

This is how I use it across domains...

  • Use an iframe from your parent domain - say parent.example
  • Then on each child.example domain, just do a postMessage to your parent.example iframe
  • All you need to do is setup a protocol of how to interpret your postMessage messages to talk to the parent.example iframe.
like image 112
Mayank Jain Avatar answered Dec 09 '22 16:12

Mayank Jain