1
Iam構建我想捕獲窗口事件的擴展。我有這樣的代碼: .............................................Firefox中的窗口觀察器
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("[email protected]");
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不是已打開的最後一個窗口?
任何想法?
你在那裏有一個語法錯誤:在register:function(){'你不應該有'},'那裏。 –
這不是問題 – Tony
窗口事件是什麼意思?你只是想看'http-on-modify-request'和'頂層窗口準備好'嗎? – Noitidart