onPageLoad is not working properly in Firefox Extension Development
Posted
by
Tharaka Deshan
on Stack Overflow
See other posts from Stack Overflow
or by Tharaka Deshan
Published on 2012-05-29T14:06:53Z
Indexed on
2012/06/11
10:40 UTC
Read the original article
Hit count: 195
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.
© Stack Overflow or respective owner