Does CORS affects localStorage?

2019-07-24 14:09发布

问题:

Searched everywhere and didn't find straight answer.
Does CORS make cross-(sub)domain localStorage sharing possible or not?
And how about on IE8?

回答1:

No, you cannot directly access another origin's storage, regardless of CORS settings.

You could however have a remote AJAX service that could store your settings on the remote domain.

e.g. Say your main website www.maindomain.com returns header Access-Control-Allow-Origin: https://www.subsite.com for its AJAX requests.

Then your other website www.subsite.com can make an AJAX request to e.g. https://www.maindomain.com/storage to retrieve or to save details cross-origin. The local storage for www.maindomain.com can be returned as a JSON object in the response for www.subsite.com to use.