Reputation: 2296
I'm trying to set an onLoad
event to the current web page from a firefox extension. I'm using the gBrowser
object but I'm not sure if this is the best way. I would like to set an onLoad
event to the web page window to execute some actions of the plugin as soon as the page is loaded.
Thanks in advance.
Upvotes: 2
Views: 817
Reputation: 2296
After several attempts I found a solution for this. Lets say we have a function
called pageLoaded
, which is the one we want to call when the website has been totally loaded. Now, we have to add an event listener to the gBrowser
object to catch the load
event.
Here the code:
function pageLoaded(){
alert("the page has been loaded")
}
gBrowser.addEventListener("load", pageLoaded, true);
I recommend to use add an event listener to the extension document before to add it to the gBrowser. The result would be something like this:
window.addEventListener("load", function () {
gBrowser.addEventListener("load", pageLoaded, true);
}, false);
I hope this solution will be useful for someone.
Thanks for reading.
Upvotes: 1