How to detect when a page is loaded (in any tab) with a firefox extension (automatically, no start-button or anything) (and display an alert message for example) ?
https://developer.mozilla.org/en/Code_snippets/On_page_load
Dont miss this part: "
Current Firefox trunk nightlies will fire the onPageLoad function for not only documents, but xul:images (favicons in tabbrowser). If you only want to handle documents, ensure aEvent.originalTarget.nodeName == "#document" 1.
"
function startup() {
mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
mainWindow.getBrowser().addEventListener("load", listener, false);
// Sidebar is loaded and mainwindow is ready
}
var listener = function(e){
alert("Hai");
//To remove event listener
//mainWindow.getBrowser().removeEventListener("load",listener, false);
}
window.addEventListener("load", startup, false);
This is code is enough for this purpose.
Though this is late, I'm answering this question to minimize the search time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With