2

我需要知道,是否有可能以任何方式存储来自我可以在每个网站上使用的 chrome 扩展程序的数据。我使用 JS conent_scripts 中的数据。

我尝试了用于 localStorage 解决方法的 cookie 和 iframe,如下所述:http: //www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/

但没有什么真正奏效。请帮我。

编辑:正如下面在评论中所写,它现在可以与 chrome.storage 一起使用。谢谢!

Edit2:这对我不起作用:

chrome.storage.sync.set({key: "test", value: "test Test 1234"},
                        function ()
                        {
                             console.log("had saved!");
                             chrome.storage.sync.get("test",
                                                     function (value)
                                                     {
                                                          console.log("read value: ", value);
                                                     }
                                                 );
                         }
                     );

控制台输出:

读取值:对象 {}

4

1 回答 1

1

您的新代码的问题如下:

chrome.storage.sync.set({test: "test Test 1234"}, function () {
    console.log("had saved!");
    chrome.storage.sync.get("test", function (value) { console.log("read value: ", value.test); } );
});

所有对象都是键值对,您不应该添加键和值属性。

于 2013-10-25T13:10:28.193 回答