抓住弹出窗口,并在Firefox通知用户(Catch popup window and notify

2019-10-21 09:14发布

有一个网站,随机显示在他们的网站上的一些活动弹出窗口。 这将是非常有用的,如果用户将被通知当一个弹出窗口显示了在Firefox中该站点等。它可以可以使用JavaScript的帮助下,或任何附加等?

Answer 1:

两种选择。

nsIWindowWatcher - https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIWindowWatcher

nsiWindowMediator - https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator

这是nsiwindowmediator方式:

/*start - windowlistener*/
var windowListener = {
    onOpenWindow: function (aXULWindow) {
        // Wait for the window to finish loading
        let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
        aDOMWindow.addEventListener('load', function () {
            aDOMWindow.removeEventListener('load', arguments.callee, false);
            //window loaded, now the website will load so addeventlistener for that
            //check what the website loading is here, if its your campain thing then block it
        }, false);
    },
    onCloseWindow: function (aXULWindow) {},
    onWindowTitleChange: function (aXULWindow, aNewTitle) {},
};
/*end - windowlistener*/

Services.wm.addListener(windowListener);
//Services.wm.removeListener(windowListener);

所以现在在onOpenWindow,你可以看到什么是开窗器,如果是该网站,则关闭该窗口。



文章来源: Catch popup window and notify user in Firefox