onPageLoad is not working properly in Firefox Extension Development
- by Tharaka Deshan
I am new to Firefox Extension Development and doing my 1st program.
Simply I needed to pop up a alert once it loaded the page.
My code was like this:
var myExtension = {
init: function() {
if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
},
onPageLoad: function(aEvent) {
alert("Loaded");
}
}
window.addEventListener("load", function load(event){
window.removeEventListener("load", load, false);
myExtension.init();
},false);
But I am getting the alert box for couple of times.
Then I found about "#document" and then I added a IF condition:
onPageLoad: function(aEvent) {
if (aEvent.originalTarget.nodeName == '#document') {
alert("Loaded");
}
}
Unfortunately still I am getting the same.
Please advise me on this.