简体   繁体   English

如何在chrome扩展程序中保存用户输入?

[英]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.

相关问题 如何在Chrome扩展程序中本地保存信息? - How can I save information locally in my chrome extension? 如何在 chrome 扩展中保存值? - How can i save values in a chrome extension? 如何修改用户提交的带有Chrome扩展程序的搜索输入中的查询? - How can I modify the query from a user submitted search input with a Chrome extension? 如何从chrome扩展程序中打开标签页,等待用户输入并返回扩展程序? - how do I, from chrome extension, open tab wait for user input and go back to extension? 保存输入字段Chrome扩展程序 - Save input fields Chrome extension 如何使用javascript在chrome扩展程序中创建会话? - How can I create session in my chrome extension using javascript? 如何验证Chrome扩展程序中的标签页ID? - How can I validate a tab id in my Chrome Extension? 如何将PhantomJS添加到我的Chrome扩展程序中? - How Can I Add PhantomJS to My Chrome Extension? "<i>How can I fetch data in my content script?<\/i>如何在我的内容脚本中获取数据?<\/b> <i>(chrome extension)<\/i> (镀铬扩展)<\/b>" - How can I fetch data in my content script? (chrome extension) 如何在带有 Manifest 3 的 Google Chrome 扩展程序中使用 JQuery? - How can I use JQuery in my Google Chrome extension with Manifest 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM