在子域之间使用localStorage [英] use localStorage across subdomains

查看:245
本文介绍了在子域之间使用localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用(IE以外的任何人)。问题是 site.com www site.com 存储他们自己独立的localStorage对象。我相信www被认为是一个子域名(如果你问我,这是一个愚蠢的决定)。如果用户最初访问 site.com 并决定在下次访问时输入 www site.com ,那么她的所有个人数据都会无法进入。如何让所有子域与主域共享相同的localStorage?

I'm replacing cookies with localStorage on browsers that can support it (anyone but IE). The problem is site.com and www.site.com store their own separate localStorage objects. I believe www is considered a subdomain (a stupid decision if you ask me). If a user was originally on site.com and decides to type in www.site.com on her next visit, all her personal data will be inaccessible. How do I get all my "subdomains" to share the same localStorage as the main domain?

推荐答案

这就是我使用它的方式跨域...

This is how I use it across domains...


  • 使用父域中的iframe - 比如parent.com

  • 然后在每个child.com域上,只需对你的parent.com iframe执行postMessage

  • 你需要做的就是设置一个如何解释你的postMessage消息与父母交谈的协议.com iframe。

我希望它有所帮助:)

这篇关于在子域之间使用localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆