1
윈도우 이벤트를 캡처하고자하는 확장 기능을 빌드하고 있습니다. 이 코드를 가지고 : .....................................파이어 폭스의 윈도우 옵저버
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가 열려있는 마지막 창이 아닙니다.
아이디어가 있으십니까?
거기에 문법 오류가 있습니다 : before'register : function() {'거기에'} '가 없어야합니다. –
문제가되지 않습니다 – Tony
윈도우 이벤트 란 무엇입니까? 'http-on-modify-request'와'toplevel-window-ready'를보고 싶습니까? – Noitidart