可以跨子域共享HTML5数据库和localStorage吗? [英] Can HTML5 databases and localStorage be shared across subdomains?

查看:1382
本文介绍了可以跨子域共享HTML5数据库和localStorage吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Safari在子网域之间共享数据。我想使用HTML5数据库(特别是 localStorage ,因为我的数据不过是键值对)。但是,似乎无法从 sub.domain.com (或反之亦然)访问存储到 domain.com 的数据。在这种情况下,是否有任何方法可以共享单个数据库?

I am attempting to share data across subdomains using Safari. I would like to use an HTML5 database (specifically localStorage as my data is nothing but key-value pairs). However, it seems as though data stored to domain.com can not be accessed from sub.domain.com (or vice versa). Is there any way to share a single database in this situation?

推荐答案

创建将作为托管在您试图访问的域上的代理 iframe 的简单页面,向该iframe发送 PostMessage ,并在iframe中执行LocalStorage数据库操作。这是一个指向使用lcoalStorage执行此操作的文章的链接 。这里是演示,发送消息到不同的页面在子域检查源代码,它使用iframe和PostMessage 。

There is simple way to use cross-domain anything, just create simple page that will be included as proxy iframe hosted on domain you try to access, send PostMessage to that iframe and inside iframe you do your LocalStorage database manipulation. Here is a link to article that do this with lcoalStorage. And here is demo that send message to different page in subdomain check the source code, it use iframe and PostMessage.

这篇关于可以跨子域共享HTML5数据库和localStorage吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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