3

I have a simple form with a text input field, for example asking for a Name. The javascript on the page is:

var fullName = document.getElementById('fullName').value

and then add to the localStorage using:

localStorage.setItem('fullName', fullName);

when I run this in my browser and type localStorage on the same tab, i get my input returned, however if i run localStorage on a different tab, the stored data is not showing up. Am I doing something wrong? thanks in advance

Harvey
  • 39
  • 6
  • 1
    Is the other tab opened to a page on the same domain? – James Thorpe Sep 11 '17 at 16:04
  • 1
    Both tab must be in the same domain – Rakib Sep 11 '17 at 16:06
  • @JamesThorpe ah I believe that is the problem, is there a way i can select which domains have access to the storage? – Harvey Sep 11 '17 at 16:09
  • No - [as per the spec](https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage), _"User agents must have a set of local storage areas, one for each origin."_ However, if you're able to change/write code on both domains, [there are alternatives](https://stackoverflow.com/questions/33957477/cross-domain-localstorage-with-javascript). – James Thorpe Sep 11 '17 at 16:10
  • @Harvey No way. Just pages from same domain have access to same items. –  Sep 11 '17 at 16:11
  • Thank you all for the help. I understand localstorage is not what im looking to use. Can anyone else suggest a way i can pass data from one tab to another? – Harvey Sep 11 '17 at 16:14
  • you can always use cookies – Ramin Ahmadi Sep 11 '17 at 16:48

0 Answers0