简体   繁体   中英

How to access window object from XUL?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM