gpt4 book ai didi

javascript - 火狐插件-sdk : get element of attached panel

转载 作者:行者123 更新时间:2023-11-28 19:42:21 26 4
gpt4 key购买 nike

我有一个非常简单的 Firefox 插件 - 使用 addon-sdk 开发。在教程中,我发现提到了切换按钮的附加面板,但我找不到一种方法(例如)在此面板中对按钮进行 onclick 回调。

这是简化的面板:

    <body>
<table width="100%">
<tr>
<td colspan="2" align="center">
<input type="button" id="btnInject" value="Inject!">
</td>
</tr>
</table>
</body>
</html>

这是 main.js 文件的一部分:

var self = require("sdk/self");
var tabs = require("sdk/tabs");

var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var self = require("sdk/self");

var button = ToggleButton({
id: "my-button",
label: "my button",
icon: {
"16": "./icon-16.png",
},
onChange: handleChange
});

var panel = panels.Panel({
contentURL: self.data.url("popup.html"),
onHide: handleHide
});

function handleChange(state) {
if (state.checked) {
panel.show({
position: button
});
}
}

function handleHide() {
button.state('window', {checked: false});
}

我需要分配 onclick 函数,我尝试过 panel.getElementById('btnInject').onclick,但找不到 getElementById 作为函数。还尝试了文档对象,但它也没有定义。

谁能帮我,如何访问这个元素?

最佳答案

您无权直接访问面板的 DOM。相反,您需要 attach a small content script并使用 panel.port 将消息发送回 main.js API。

请参阅Communicating using port文档以获取更多信息。

关于javascript - 火狐插件-sdk : get element of attached panel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24843453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com