0

I'm using the nsIWebProgressListener interface to find out if a url has been changed. If it has, I'd like to rewrite the link. Here's a snippet (code taken from the bottom of the page from the link above)


var myExt_urlBarListener = {
  QueryInterface: function(aIID)
  {
   if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
       aIID.equals(Components.interfaces.nsISupports))
     return this;
   throw Components.results.NS_NOINTERFACE;
  },

  onLocationChange: function(aProgress, aRequest, aURI)
  {
    myExtension.processNewURL(aURI);
  },

  onStateChange: function(a, b, c, d) {},
  onProgressChange: function(a, b, c, d, e, f) {},
  onStatusChange: function(a, b, c, d) {},
  onSecurityChange: function(a, b, c) {}
};

var myExtension = {
  oldURL: null,

  init: function() {
    // Listen for webpage loads
    gBrowser.addProgressListener(myExt_urlBarListener,
        Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
  },

  uninit: function() {
    gBrowser.removeProgressListener(myExt_urlBarListener);
  },

  processNewURL: function(aURI) {
    if (aURI.spec == this.oldURL)
      return;

    // now we know the url is new...
    start_work(aURI.spec);
    this.oldURL = aURI.spec;
  }
};

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

And a function to handle the change:


function start_work(url)
{
    result = check(url);
    if (result) {
            setCookie('bws', 'true', 1, '/');
            window.location = result; // or window.location.replace, doesn't matter
        }
}

Here's what happens! alt text http://grab.by/20eP As you can see the entire browser/address bar/chrome disappeared!

Any help on this?

0

1 Answer 1

2

simple: add window.content.location

1
  • 1
    Yes. In this case, his code is in the chrome context, so window points to the chrome window which is the browser UI.
    – sdwilsh
    Jan 27, 2010 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.