I've tried with Firefox 4.0 to use the localStorage object to save a few values used to fill the form at http://host1.example.com/index.html and to fetch those values to automatically fill the same form at http://host2.example.com/index.html but it doesn't work.
Does the same origin policy applies to the url instead of the domain?
CORS is a relaxation of the same-origin policy implemented in modern browsers. Without features like CORS, websites are restricted to accessing resources from the same origin through what is known as same-origin policy.
A webpage inside an iframe/frame is not allowed to modify or access the DOM of its parent or top page and vice-versa if both pages don't belong to same origin. A frame or child page can bypass this restriction by setting window. document. domain variable to the same domain name as the parent's domain name.
The same-origin policy is a foundational building block of web security. It essentially defines protection domains which are used to restrict actions and access to web resources. One such restriction is that scrips executing on http://example.com are not allowed to access resources on http://subdomain.example.com .
The same-origin policy restricts which network messages one origin can send to another. For example, the same-origin policy allows inter-origin HTTP requests with GET and POST methods but denies inter-origin PUT and DELETE requests.
No, it applies to hosts. You could try setting document.domain
before you create or retrieve your localStorage
objects:
document.domain = "example.com";
--edit
OK, though you can set document.domain
that has no impact on localStorage
. It is possible to hack together a solution using iframe
and cross document messaging: Cross-domain localStorage
you're out of luck. localStorage cannot be shared between different domains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With