Because iPad/iPhone doesn't support cookies from third party sites, I want to store values in localStorage. An example on domainA might be:
<script src="http://domainB/something.js"></script>
this script on domainB can access window.localStorage and it works great. However the values are stored in domainA because that's the document's location.
If I put my script inside an iframe whose source is on domainB, then it works, but I'm trying to avoid frames. So my question is: Is there a way to get/set values in localStorage on a remote domain such that they'll be there when I visit domainB at a later time?
Because iPad/iPhone doesn't support cookies from third party sites, I want to store values in localStorage. An example on domainA might be:
<script src="http://domainB/something.js"></script>
this script on domainB can access window.localStorage and it works great. However the values are stored in domainA because that's the document's location.
If I put my script inside an iframe whose source is on domainB, then it works, but I'm trying to avoid frames. So my question is: Is there a way to get/set values in localStorage on a remote domain such that they'll be there when I visit domainB at a later time?
Share Improve this question asked Dec 1, 2010 at 19:29 Jody PowletteJody Powlette 1,6033 gold badges18 silver badges21 bronze badges 3- Dude, read your own question: local storage on a remote domain :) Just joking, I know what you mean. Don't know the answer though. But I'm with Jan on this one(+1) – Jan Commented Dec 1, 2010 at 22:02
- Well they don't call them remoteCookies, but they exist in the domain that set them, even when set through a url referred from the prior domain. Was hoping to acplish something similar. Simply changing it from script to iframe containing a script solves it, but was hoping for something more elegant. – Jody Powlette Commented Dec 1, 2010 at 22:08
- Here is article about Cross-Domain localStorage nczonline/blog/2010/09/07/… using iFrames – jcubic Commented Jun 20, 2014 at 8:08
1 Answer
Reset to default 5This isn't possible without your iframe workaround.
The ability to access the same localStorage object from multiple domains would violate the Same origin policy,and the spec:
User agents must raise a SECURITY_ERR exception whenever any of the members of a Storage object originally returned by the localStorage attribute are accessed by scripts whose effective script origin is not the same as the origin of the Document of the Window object on which the localStorage attribute was accessed.
http://dev.w3/html5/webstorage/#security-localStorage
If this wasn't for iPhone, I would suggest a flash solution. But with localStorage, I think you are out of luck until they implement a cross-domain policy.