CORS是否影响localStorage? [英] Does CORS affects localStorage?
问题描述
搜索无处不在,没有找到直接的答案。
CORS是否可以使跨域(local)域的localStorage共享成为可能?
在IE8上怎么样?
Searched everywhere and didn't find straight answer.
Does CORS make cross-(sub)domain localStorage sharing possible or not?
And how about on IE8?
推荐答案
否,您无法直接访问其他来源的存储空间,无论CORS设置如何。
No, you cannot directly access another origin's storage, regardless of CORS settings.
不过,您可以使用远程AJAX服务,将您的设置存储在远程域。
You could however have a remote AJAX service that could store your settings on the remote domain.
例如说出您的主要网站 www.maindomain.com
返回标题 Access-Control-Allow-Origin:https://www.subsite.com $
e.g. Say your main website www.maindomain.com
returns header Access-Control-Allow-Origin: https://www.subsite.com
for its AJAX requests.
然后您的其他网站 www.subsite.com
可以创建一个AJAX请求到例如 https://www.maindomain.com/storage
可检索或保存跨原产地的详细信息。 www.maindomain.com
的本地存储可以在 www.subsite.com
使用。
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.
这篇关于CORS是否影响localStorage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!