开发者

Mozilla Browser exit Observer

开发者 https://www.devze.com 2023-01-28 11:14 出处:网络
I have implement \"quit-application\" Observer, TestApp.ns(function() { with (TestApp.Lib) { //Ci = Components.interfaces;

I have implement "quit-application" Observer,

TestApp.ns(function() {
with (TestApp.Lib) {

    //Ci = Components.interfaces;

    theApp.ExitObserver = function() {},

    // Called on uninstall
    theApp.ExitObserver.prototype.observe = function(subject, topic, data){
        if (topic == "quit-application"){
            alert(" exit ");
        }

    };
    }
});

Im My Main.js fil开发者_JAVA技巧e i called this ExitObserver as bellow.

theApp.exitObserver = new theApp.ExitObserver();
observerService.addObserver(theApp.exitObserver, "quit-application", false);

When user exit from browser my alert not working. Is there any issue in this implementation?


I would suggest simplifying your code first. Try this:

var observerService = Components.classes["@mozilla.org/observer-service;1"]
                      .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(
    {
        observe: function(subject, topic, data) {
            alert(topic);
        }
    }, "quit-application", false);

I'm afraid I can't test this on my platform, so forgive me for any typos. Please let me know what you run into!

See also this thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消