How can I use local storage? setItem in one application, and how can I get local storage? getItem in another application
1.Application
let data="This is Session"
localstorage.setItem("myurl",data)
2.Application
const newdata = localstorage.getItem("myurl")
I am expecting This is session, but it’s getting null. How can I solve the problem?
3
Answers
localStorage is subject to the same-origin policy, which means that data stored in localStorage is accessible only to web pages from the same domain and protocol (e.g., http://example.com). Different applications typically have different domains or protocols, which would prevent them from sharing data in localStorage.
You cannot access items from localstorage of other domains.
You can’t, because, I think, the localstorage is restricted by the hostname, protocol and port.
But maybe you can try this hack : webmessaging :
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
http://www.w3.org/TR/webmessaging/
As stated in MDN:
Therefore, no, you cannot, unless you use the same domain and port. However, what you could do is use cookies, as they were designed for cross-application usage.