我正在使用插件 SDK 创建一个 Firefox 扩展,它会打开一个包含当前页面信息的 iframe。对 iframe 进行一些操作后,我需要关闭面板对象,但我不知道如何通过管道传输此消息。有任何想法吗?在 Chrome 中,我只需关闭窗口,扩展程序就会关闭。
代码:https://github.com/kippt/kippt-firefox/blob/master/lib/main.js
最佳答案
恐怕您必须创建一个内容脚本,该脚本会注册一个监听器,以便在您想要关闭面板时调用。内容脚本应通过 self.port.emit('your-event-name')
与插件通信,并且附加代码应通过 panel.port.on('your-event-name')
监听通知关闭面板:
var kipptPanel = require("panel").Panel({
width:400,
height:245,
// The contentURL should do this to close the panel:
// <button id="close-button">self.port.emit('close', null)</button>
contentURL : "http://localhost:8000/test-panel.html",
contentScript: "document.getElementById('close-button').addEventListener('click', function() {" +
" console.log('zz');self.port.emit('close', null);" +
"});"
});
kipptPanel.port.on("close", function (text) {
console.log(text);
kipptPanel.destroy();
});
kipptPanel.show();
这是一个modified version of your code in the add-on builder .
这在SDK's panel documentation中有描述。 .
我发现这太复杂了,你可能想在jetpack群里问一下是否制作window.close()
已考虑关闭面板。
关于javascript - 在 Firefox 附加组件中从 iframe 关闭面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9749127/