实现nsIObserver var testObserver = { observe: function(subject, topic, data) { alert(topic+data); if (topic != "testTopic") { return; } }}; 调用 nsIObserverServicefunction testObserverService(){ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var obj = Components.classes["@mozilla.org/observer-service;1"]. getService(Components.interfaces.nsIObserverService); obj.addObserver(testObserver,"testTopic",false); obj.notifyObservers( null,"testTopic","start") obj.removeObserver(testObserver, "testTopic"); }