【发布时间】:2018-06-10 05:37:29
【问题描述】:
所以,我有一个输入 popup.html。如果您输入数据,popup.js 会将数据发送到content.js,并且它已经更改了选项卡上的某些内容。但是在更新选项卡后,选项卡上的更改就消失了。您如何做到这一点,以便它们只有在将新数据输入input 时才会保留和更改?
popup.html и popup.js
var input = document.querySelector('#inp');
var text = document.querySelector("#text");
var button = document.querySelector("#btn");
btn.addEventListener('click', function() {
var inp = input.value;
chrome.tabs.query({active: true, currentWindow: true}, function(foundTabs) {
const activeTab = foundTabs[0];
chrome.tabs.sendMessage(activeTab.id, {text: inp});//sending value of input
})
});
<input type="text" id="inp">
<button id="btn">Send</button>
content.js:
chrome.runtime.onMessage.addListener(function(request) {
const txt = request.text; //get input value
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
//insert in html
});
});
【问题讨论】:
标签: javascript jquery html google-chrome-extension extension-methods