从子域访问根域的localStorage [英] Access root domain's localStorage from subdomain

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

问题描述

为了简单起见:

我有一个简单的UserJS脚本( FF / Chrome:Greasemonkey,Opera:内置)修复了我经常使用的网站上的一些问题。问题是我需要在不同的请求之间存储一些数据。我的第一次尝试是 LocalStorage ,但它在使用子域时失败: www.domain.com subdomain.domain.com (不幸的是,root-domain实际上是子域名 - 愚蠢 www )。我需要能够访问一些可在任何地方使用的数据源。

I've got a simple UserJS script (FF/Chrome: Greasemonkey, Opera: built-in) that fixes some issues on website I'm using quite often. The problem is that I need to store some data between different requests. My first attempt was LocalStorage but it fail when it came to work with subdomains: www.domain.com and subdomain.domain.com (unfortunately root-domain is subdomain in fact - stupid www) . I need to be able to access some data source that would be available everywhere.

现在我卡住了 - 有什么想法吗?

Now I'm stuck - any ideas?

推荐答案

...为什么不使用 GM_setValue GM_getValue

...Why not use GM_setValue and GM_getValue?

编辑:我做了一点挖掘。看看我找到了什么!

I did a little digging. Look what I found!

http://www.opera.com/docs/userjs/specs/#scriptstorage

它声称与localStorage的工作方式相同,但它的范围是-script,而不是每个网站。应该适合您的用例。

It claims to work the same as localStorage, but it's scoped per-script, rather than per-website. Should work perfect for your use case.

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

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