我的Chrome扩展程序弹出窗口中有一个文本区域和一个按钮.我希望用户在文本区域中输入所需的文本.然后,一旦他们点击该按钮,它将注入一个内容脚本,以更改当前页面上的字段<textarea class="comments">文本,该文本必须是用户<textarea>在Chrome扩展程序弹出窗口中输入的文本.
我的问题是,我怎样才能从文本<textarea>中我popup.html,并从它传递popup.js的内容脚本?
这就是我目前所拥有的:
popup.html:
<!doctype html>
<html>
<head><title>activity</title></head>
<body>
<button id="clickactivity3">N/A</button>
<textarea rows="4" cols="10" id="comments" placeholder="N/A Reason..."></textarea>
<script src="popup.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
popup.js:
function injectTheScript3() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// query the active tab, which will be only one tab
//and inject the script in it
chrome.tabs.executeScript(tabs[0].id, {file: "content_script3.js"});
});
}
document.getElementById('clickactivity3').addEventListener('click', injectTheScript3);
Run Code Online (Sandbox Code Playgroud)
content_script3:
//returns a node list which is good
var objSelectComments = …Run Code Online (Sandbox Code Playgroud) html javascript google-chrome-extension firefox-addon-webextensions