ユーザーが入力したデータをテキストエリア内に保存しようとしていますpopup.html
。データに対して jQuery を使用するwindow unload
と、同期する必要がありwindow ready
、データを復元する必要があります。ただし、popup.html
テキストエリアのコンテンツを開くとundefined
. これは、私がロードしているjQueryコードですpopup.html
:
$(window).unload (
function save() {
var textarea = document.querySelector("#contacts").value;
// Old method of storing data locally
//localStorage["contacts"] = textarea.value;
// Save data using the Chrome extension storage API.
chrome.storage.sync.set({contacts: textarea}, function() {
console.log("Contacts saved");
});
});
$(window).ready(
function restore() {
var textarea = document.querySelector("#contacts");
// Old method of retrieving data locally
// var content = localStorage["contacts"];
chrome.storage.sync.get('contacts', function(r) {
console.log("Contacts retrieved");
var content = r["contacts"];
textarea.value = content;
});
});