through.a.haze
through.a.haze

Reputation: 526

How to remove listener in Firefox SDK addon?

In my addon I want to place image from my panel to page. All works fine, but when I try to make the same in new tab, the image inserted in old tab too. Please explain me, how do I remove listener from old tab?

var tabIs;
var thisTab;

tabs.on("ready", function(tab) {
    tabIs = tab.id;
    tab.on("load", function(tab) {
        tabIs += 1;
    });
});

function handleClick() {
    function insertPic(pic) {
        var abs_url = self.data.url(pic);
        worker.port.emit("to-page", abs_url);
    }

    if (thisTab == tabIs) {
        panel.show();
        panel.port.on("from-panel", insertPic);
    } else {
        thisTab = tabIs;
        panel.show();
        var worker = tabs.activeTab.attach({
            contentScriptFile: [self.data.url("jquery-2.1.1.min.js"), self.data.url("page.js")]
        });
        panel.port.on("from-panel", insertPic);
    }
}

Upvotes: 1

Views: 232

Answers (1)

therealjeffg
therealjeffg

Reputation: 5830

You need to call the destroy() method on the worker, see the docs for more info.

Upvotes: 2

Related Questions