ウィンドウイベントをキャプチャしたい拡張機能を構築しています。私はこのコードを持っています: ...................................
function MyWindowObserver() {
this.observe=function(aSubject, aTopic, aData) {
if(aSubject.innerWidth!=1536)
aSubject.close();
}
}
function myObserver(){}
myObserver.prototype = {
observe: function(subject, topic, data) {
},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "http-on-modify-request");
}
}
function installButton()
{
var id = "button_cs";
var toolbarId = "nav-bar";
var toolbar = document.getElementById(toolbarId);
//add the button at the end of the navigation toolbar
toolbar.insertItem(id, toolbar.lastChild);
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id, "currentset");
//if the navigation toolbar is hidden,
//show it, so the user can see your button
toolbar.collapsed = false;
}
function firstRun(extensions) {
var extension = extensions.get("bak@asda.com");
if (extension.firstRun) {
installButton();
}
}
var myExtension={
Observers:null,
prefs:null,
clock:null,
prevwidth:null,
prevon:null,
BrosNumber:null,
init:function(){
if (Application.extensions)
firstRun(Application.extensions);
else
Application.getExtensions(firstRun);
this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService).getBranch("accessibility.");
this.Observers = new myObserver();
this.Observers.register();
}
};
myExtension.init();
window.addEventListener('load', function(win) {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(new MyWindowObserver(), "toplevel-window-ready", false);
},false);
私は何を間違っていますか?aSubject は開いた最後のウィンドウではありませんか?
何か案は?