2

How I store date on chrome. I tried localstorage but stupid reason they won't it allow. I tied cookies but no. Is away store any data at all. I tried chrome.storage but that not defined. How do I fix this?

4

2 回答 2

3

您应该chrome.storage与您的扩展一起使用。如果没有看到您的代码,我无法告诉您您做错了什么,但请确保您在清单中正确设置了权限:

{
  "name": "My extension",
   ...
  "permissions": [
  "storage"
],
...
}

请提供一个示例,说明您如何尝试访问chrome.storagelocalStorage.

于 2013-11-01T02:39:45.363 回答
2

朋友你也需要分享代码。如果我清楚地理解你的问题,你应该这样

  var car = {};
    car.wheels = 4;
    car.doors = 2;
    car.sound = 'vroom';
    car.name = 'Lightning McQueen';
    console.log( car );
    localStorage.setItem( 'car', car );
    console.log( JSON.parse( localStorage.getItem( 'car' ) ) );

这就是如何使用本地存储。如果仍然有问题,请使用 window.localStorage.setItem 和 window.localStorage.getItem

于 2013-11-01T02:47:00.980 回答