![](/img/trans.png)
[英]Chrome extension is not sending the data from the popup to my node.js/express server
[英]chrome extension: sending data from popup to unlink js file
即時通訊與chrome擴展混為一談。 我有一個popup html
中執行的litell表單,我正在嘗試用用戶輸入來完成。 我在popup.html
鏈接了一個文件,其中popup.html
此功能:
function click(e) {
chrome.tabs.executeScript(null, {
file: "theJs.js"
});
}
現在,在文件theJs.js
,我編寫了要在正在運行的當前選項卡上執行的代碼(可以在當前選項卡上獲取並設置信息)。
所以我的問題是:
如何從popup.html
獲取信息,並將其發送到theJs.js
文件,以便可以使用當前選項卡上的用戶輸入?
可能嗎?
(對不起我的英語不好)
使用消息傳遞
content.js
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.type == 'apply') {
applySettings(request.settings);
sendResponse();
}
});
popup.js
chrome.tabs.getSelected(function(tab) {
chrome.tabs.sendRequest(tab.id, { type: "apply", name: name, settings: settings },
function(response) {
showMessage('success', '<strong>' + name + '</strong> applied.');
}
);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.