[英]How can I save user input in my chrome extension?
I'm making a Chrome countdown clock extension and I want to save the user input in javascript, is there anyway to do this? 我正在做一个Chrome倒数时钟扩展,我想用javascript保存用户输入,无论如何要这样做?
here is the code, 这是代码,
var userInput = prompt ("Enter Your Date");
var countDownDate = new Date(userInput).getTime();
You can use chrome.storage function from google libraries. 您可以使用Google库中的chrome.storage函数。
chrome.storage.sync to syncronise the data with your google account chrome.storage.sync与您的Google帐户同步数据
chrome.storage.local for not syncronising. chrome.storage.local用于不同步。
set is used to set the variables set用于设置变量
get is used to take the variables. get用于获取变量。
to set the variable in one page: 在一页中设置变量:
chrome.storage.sync.set({'nameInTheStorage' : jsVariables}, function(){
if(chrome.runtime.error){
console.log("Error.");
}
});
to get the variables in another page: 在另一个页面中获取变量:
chrome.storage.sync.get('nameInTheStorage', function(items){
if(!chrome.runtime.error){
//do what you want to do with the data
var x = items.nameInTheStorage;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.