Reputation: 788
I'm creating a Firefox extension with addons SDK which open an iframe with information from the current page. After some actions to iframe I would need to close the Panel object but I don't know how to pipe this message. Any ideas? In Chrome I was able to just close the window and extension would close.
The code: https://github.com/kippt/kippt-firefox/blob/master/lib/main.js
Upvotes: 2
Views: 749
Reputation: 32063
I'm afraid you'll have to create a content script, which registers a listener to be called when you want to close the panel. The content script should communicate with the addon via self.port.emit('your-event-name')
, and the add-on code should listen for the notification via panel.port.on('your-event-name')
to close the panel:
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();
Here's a modified version of your code in the add-on builder.
This is described at the SDK's panel documentation.
I realize it's too complicated, you might want to ask in the jetpack group if making window.close()
close the panel has been considered.
Upvotes: 2