Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 Storage's same origin policy

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?

like image 673
alessmar Avatar asked Jul 11 '11 05:07

alessmar


People also ask

Do I need CORS for same origin?

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.

How do I get around the same origin problem with iframe?

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.

Does same-origin policy apply to subdomains?

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 .

What is same-origin policy example?

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.


2 Answers

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

like image 66
robertc Avatar answered Sep 18 '22 08:09

robertc


you're out of luck. localStorage cannot be shared between different domains.

like image 28
Nathan Bubna Avatar answered Sep 20 '22 08:09

Nathan Bubna