Richard H
Richard H

Reputation: 39055

gBrowser.addEventListener: "load" event fired three times

I have installed the "hello world" dev example for Firefox extensions as described here: http://blog.mozilla.com/addons/2009/01/28/how-to-develop-a-firefox-extension/

I have modified the anonymous function that gets passed to gBrowser.addEventListener:

gBrowser.addEventListener("load", function (event) {

    var t = event.target;
    alert("Content title: " + t.contentTitle);          

}, false);

This function is getting called three times for every page load. When I click a link, it fires twice for the current (already loaded page) and once for the new page.

I have uninstalled all other addons (including Firebug) and still it fires 3 times. Does anyone know why this might be?

Thanks Richard

Upvotes: 2

Views: 3141

Answers (1)

user2630493
user2630493

Reputation: 11

I would recommend you to do something like this:

window.addEventListener("load", function load() {
                    window.removeEventListener("load",load,false); //no longer needed
                    window.gBrowser.addEventListener('DOMContentLoaded', function load(event) {
                    your_addon.init_function(event);
                    }, false);

In my addon it works. :-)

Hope this helps.

Michał

Upvotes: 1

Related Questions