Google chrome extension: local storage

后端 未结 2 1269
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 05:43

I\'m developing an extension for Google Chrome, and have run into some trouble.I created an options.html page and added it to the manifest.json file.The page shows properly.

相关标签:
2条回答
  • 2020-12-08 06:02

    The correct method is:

    if (typeof(localStorage) == ‘undefined’ ) {
      alert(‘Your browser does not support HTML5 localStorage. Try upgrading.’);
    }
    else {
      try {
        localStorage.setItem(“name”, “Hello World!”); //saves to the database, “key”, “value”
      }
      catch (e) {
        if (e == QUOTA_EXCEEDED_ERR) {
          alert(‘Quota exceeded!’); //data wasn’t successfully saved due to quota exceed so throw an error
        }
      }
      document.write(localStorage.getItem(“name”)); //Hello World!
      localStorage.removeItem(“name”); //deletes the matching item from the database
    }
    

    REFERENCE: http://html5tutorial.net/tutorials/working-with-html5-localstorage.html

    0 讨论(0)
  • 2020-12-08 06:03

    You can set them using either

    localStorage["var"]=data;
    

    or

    localStorage.var=data;
    

    Load them using

    var myvar = localStorage.var;
    

    You can read about the API here.

    0 讨论(0)
提交回复
热议问题