Re: Finding events on a page added using addEventListener

Jon <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Organization http://groups.google.com
Message-ID <0703a8f3-befb-4a24-a711-2948653f5866@q27g2000prf.googlegroups.com>
Thanks for your help ;) I came up with this solution:

function catcher(x) {
    x.addEventListenerOld = x.addEventListener;
    x.addEventListener = function(event, func, capture) {
        alert(
            "element: " + this +
            "\nevent: " + event +
            "\nfunc: " + func +
            "\ncapture: " + capture
        );
        return this.addEventListenerOld(event, func, capture);
    }
}

document.addEventListener(
    "DOMNodeInserted",
    function(e) { catcher(e.target); },
    false
);

document.addEventListener(
    "DOMContentLoaded",
    function() {
        nodes = document.getElementsByTagName("*");
        for (i = 0; i < nodes.length; i++) {
            catcher(nodes.item(i));
        }
    },
    false
);

I'm going to integrate this into my application. Its not the perfect
solution but its fine for my project. Some events could be missed if
they are triggered on DOMContentLoaded and its a bit messy ;). I think
that I will need to do some testing with DOMNodeInserted I think its
triggered if an element is moved around the DOM so that means
catcher() will be called multiple times on a node and so
addEventListenerOld will recursively call itself when an event is
added.

Also having a search through this group and bugzilla.

Thanks again!

Jon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.