Reputation: 204
I am storing a value in local storage in one domain. Can I retrieve that value from another domain if I am accessing both domain from same browser?
Upvotes: 5
Views: 22525
Reputation: 431
You may want to take a look at this blog post. It seem to suggest that you can attempt to use an iframe as a workaround to access local storage from another domain.
Disclaimer: I haven't tried it before but it seems interesting. Let me know if it works!
Upvotes: 0
Reputation: 116
Yes, you can use this javascript library. Bifrost-cors size: <2KB
It's very simple to use, you just need to invoke method.
// In www.exampleA.com site:
var bifrostCors = new bifrostCors("http://exampleB.com/", false)
// In www.exampleB.com site
var bifrostCors = new bifrostCors("http://exampleA.com/", false)
bifrostCors.getLocalStorage("local-storage-key-of-what-you-want")
Actually this lib render the iframe (hidden) and uses window.postMessage to communicate with two different contexts (domain). You can also implement by yourself but this lib is very very light < 2Kb. Also not only you can access localStorage you have feature also like.
Upvotes: 2
Reputation: 81
No, you can't use the local storage of one domain to other domain. Local Storage is domain based. You can’t read or write from localstorage that’s on different domain even on it's subdomain. you can use it via Iframe on your subdomain. Please go through this article Cross-Domain LocalStorage for detailed explanation.
Hope it'll help. :)
Upvotes: 6