簡體   English   中英

chrome擴展:從彈出窗口發送數據到取消鏈接js文件

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM