我正在构建一个我想捕获窗口事件的扩展。我有这个代码: .....................
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 不是最后一个打开的窗口吗?
有任何想法吗?