Firefox 3 Extension Javascript Duplicate event listener on load
I was fixing an extension that was written for Firefox 2 to work with Firefox 3. One of the changes was to use:
window.getBrowser (). addEventListener ("load", checkURL, true);
and not just through the window.
The only problem is that the "load" event seems to happen more than once per page load. I've also tried listening for "DOMContentLoaded" but with similar results.
Is there a way to make the script load only once per page? If it matters, the pages I download are forum pages from forums.somethingawful.com.
Well, it turns out that for one, load events can be triggered when images such as an icon are loaded. Therefore, you need to make sure that the goal is indeed a document:
aEvent.originalTarget.nodeName == "#document"
More information can be found on the snippets page: https://developer.mozilla.org/En/Code_snippets/On_page_load
Try:
window.getBrowser().addProgressListener(
checkURL,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT
);
and checkLink should be an object with onStateChange function with this signature:
onStateChange: function(aProgress, request, stateFlags, status);
Have a look at the docs at nsiWebProgress .
a source to share