javascript - 在 Firefox 附加组件中从 iframe 关闭面板

标签 javascript firefox firefox-addon firefox-addon-sdk

我正在使用插件 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/

相关文章:

javascript - 如何获取当前firefox标签页的URL

Javascript,检测文本框是否有焦点?

javascript - 将事件对象传递给 firefox 中的触发函数

javascript - jquery检测文本变化

javascript - 非自调用、匿名、javascript 函数有什么意义?

javascript - 在表单部分设置超时

javascript - 即使用户没有输入任何内容,如何强制文本框为 "changed"。从 nsIFilePicker 设置的值

javascript - JQuery - 过滤以输入文本开头的标签

javascript - 无法在内容脚本中使用 jQuery ajaxComplete

javascript - 从 Firefox 扩展在页面的窗口对象中设置一个对象?