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) ?
+2
A:
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].
"
palindrom
2009-07-27 12:13:10
A:
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.
Vinothkumar Arputharaj
2010-08-10 07:48:13