Mozilla 浏览器退出观察者

发布于 2024-10-04 12:11:56 字数 614 浏览 10 评论 0原文

我已经实现了“退出应用程序”观察者,

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 ");
        }

    };
    }
});

在我的 Main.js 文件中,我将此 ExitObserver 称为如下。

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

当用户退出浏览器时,我的警报不起作用。这个实现有什么问题吗?

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 file 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-10-11 12:11:56

我建议首先简化您的代码。试试这个:

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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文