Tutorial :Detect when page loaded with firefox extension



Question:

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) ?


Solution:1

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.

"


Solution:2

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »