传输用户';在Chrome扩展中的JavaScript文件之间的输入?
这个问题是一个具体的问题。所以,我会尽可能的彻底 我这样做是为了学习如何制作能够与网站交互的Chrome扩展 这应该做的是获取输入字段的输入,即用户在其中写入的内容,然后用该文本替换网站的特定部分。我使用中所述的“简单一次性请求”,因为它有一个ID,可以通过传输用户';在Chrome扩展中的JavaScript文件之间的输入?,javascript,html,google-chrome-extension,Javascript,Html,Google Chrome Extension,这个问题是一个具体的问题。所以,我会尽可能的彻底 我这样做是为了学习如何制作能够与网站交互的Chrome扩展 这应该做的是获取输入字段的输入,即用户在其中写入的内容,然后用该文本替换网站的特定部分。我使用中所述的“简单一次性请求”,因为它有一个ID,可以通过getElementById轻松编辑 简单地在单击按钮时替换“简单的一次性请求”语句很容易,但当我尝试获取用户的输入并将其插入文档时会出现问题 这是我的密码: manifest.json: content.js: replace.js:
getElementById
轻松编辑
简单地在单击按钮时替换“简单的一次性请求”语句很容易,但当我尝试获取用户的输入并将其插入文档时会出现问题
这是我的密码:
manifest.json:
content.js:
replace.js:
menu.html:
正文{宽度:200px;}
#文本{字体大小:13px;文本对齐:居中;}
好啊
我尝试使用一个简单的存储脚本来保存值并通过文件解析它,但它只会使脚本打印出来未定义的
将输入值传递给文档的解决方案是什么
menu.js
chrome.storage.local.get
调用不正确,因此它返回undefined
,请指定键名并在回调中使用值:
var item;
chrome.storage.local.get('value', function(data) {
item = data.value;
document.getElementById('simple').innerHTML = item;
});
chrome.storage.local.set({'value': theValue}, function() {
message('value saved');
chrome.tabs.executeScript({ file: 'replace.js' });
});
关于您如何尝试使用chrome.storage.local.get(),请参阅:
var item = chrome.storage.local.get(null, function(){
message('Value gotten')
})
document.getElementById('simple').innerHTML = item;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<style>
body {width: 200px;}
#text{ font-size: 13px; text-align: center;}
</style>
<body>
<input id='input' type="text" placeholder="Text Here">
<button id='button' class='button button'>Ok</button>
<script src="content.js"></script>
</body>
</html>
var item;
chrome.storage.local.get('value', function(data) {
item = data.value;
document.getElementById('simple').innerHTML = item;
});
chrome.storage.local.set({'value': theValue}, function() {
message('value saved');
chrome.tabs.executeScript({ file: 'replace.js' });
});