views:

367

answers:

4

How can I catch the event when "a page starts to load in the Browser"?

How can I access the HTML and manipulate it with XUL?

+2  A: 

There is a large amount of documentation and sample code for this very task already on Mozilla's site. You question is a big vague though, so I may be linking you to the wrong page.

sdwilsh
A: 

No, i think his question is similar to mine. Curently, all documentation on MDC tells us how to access our "chrome" window's document but what we want is this:

  • New Browser Window (or Tab) Opens on Google.com for example
  • When Google.com's DOM has finished loading, i want to call one of my extension's functions
  • The function called wants to modify Google.com's search box (for example)

HOW?

Quickredfox
+1  A: 

This is essentially taken from the mozilla site

window.addEventListener("load", function() { myExtension.init(); }, false);

var myExtension = {

    init: function() {
    var appcontent = document.getElementById("appcontent");  
    if(appcontent)
        appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);  
    },

    onPageLoad: function(event) {
        var doc = event.originalTarget;
        var myDiv = doc.getElementById("myDiv");
        //do something interesting with it
    }
}

have fun

josiahdecker
+1  A: 

I had the same question as this. I found documentation, but had trouble getting the code to run in Firefox 3.6.12. I made some changes and managed to get it working:

this._loadHandler = function(event) {

var myDomain = 'www.yahoo.com';

let doc = event.originalTarget;
//alert(doc.defaultView.location.href);
if (doc instanceof HTMLDocument) {

    var re = new RegExp(myDomain);
    if (doc.defaultView.location.href.match(re)) {
        alert("Successful match");
    }

}};


gBrowser.addEventListener("load", this._loadHandler, true);

This was modified from the example here: https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads

HTH

Greg Jones