Guest User

Baris Derin

a guest
Mar 28th, 2009
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myObserver()
  2. {
  3.   this.register();
  4. }
  5. myObserver.prototype = {
  6.     observe: function(aSubject, aTopic, aData) {
  7.    
  8.         var oHttp = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
  9.    
  10.         if (oHttp.name.toString().indexOf("http://www.google.com/")!=-1) {
  11.    
  12.             alert(oHttp.responseStatus);
  13.             //for the case two Google tabs opened at the same time.
  14.             //200 and 404 will alert. But which one belongs to which request?
  15.    
  16.         }
  17.  
  18.     },
  19.     register: function() {
  20.     var observerService = Components.classes["@mozilla.org/observer-service;1"]
  21.                           .getService(Components.interfaces.nsIObserverService);
  22.     observerService.addObserver(this, "http-on-examine-response", false);
  23.     },
  24.     unregister: function() {
  25.     var observerService = Components.classes["@mozilla.org/observer-service;1"]
  26.                             .getService(Components.interfaces.nsIObserverService);
  27.     observerService.removeObserver(this, "http-on-examine-response");
  28.     }
  29. }
  30.  
  31.  
  32. window.addEventListener("load",function(event){observer = new myObserver();},false);
  33. window.addEventListener("unload",function(event){observer.unregister();},false);
Advertisement
Add Comment
Please, Sign In to add comment