使用Chrome扩展程序操作DOM

问题描述 投票:0回答:1

在我的Chrome扩展程序中使用弹出窗口我想打开一定数量的选项卡,加载后我想用变量操作DOM。

我可以打开选项卡,但我找不到将数据发送到选项卡的方法。

也许更好的方法是使用POST方法打开Url并直接发送数据?

popup.js

$(document).ready(function () {
    "use strict";
    $('button').on('click', function () {
        chrome.tabs.create({ windowId: window.id, url: "http://www.url1.com" }
        // manipulate the dom/form data with 2 variables, which are given
        // var1 = xxx and var2 = yyy
        chrome.tabs.create({ windowId: window.id, url: "http://www.url2.com" }
        // manipulate the dom/form data with 2 variables, which are given
        // var3 = 123 and var4 = 678

    });
});
javascript jquery google-chrome dom google-chrome-extension
1个回答
0
投票

请使用postMessage CHROME API在以下任何脚本之间发送或接收数据。

  • background.js
  • content_script.js
  • popup.js

有关详细信息,请参阅以下文档。

https://developer.chrome.com/extensions/messaging

© www.soinside.com 2019 - 2024. All rights reserved.