问题描述
|
我有一个Chrome扩展程序,该扩展程序将带有json字符串的数据存储在localStorage变量中。我正在尝试为firefox创建此扩展的版本。但是在firefox中,localStorage似乎不适用于扩展。
反正有简单地持久存储在Firefox中的json字符串吗?谢谢。
解决方法
如果您使用Firefox的Addon SDK进行扩展,则可以使用内置的简单存储模块。它公开了一个“ 0”对象,您的代码可以将其视为普通的javascript对象,但是Firefox会为您持久存储该对象。
一个简化的示例如下所示:
// load the simple storage module
var storage = require(\'simple-storage\').storage;
// write a value to the key \"bacon\"
storage.bacon = JSON.stringify({\"tasty\": \"is bacon\"});
// do stuff,retrieve the value later and pass it to a function
eat(storage.bacon);
即使在以后的会话中,storage.bacon中的值也可用于扩展。