抓住弹出窗口并在Firefox中通知用户

时间:2014-12-03 12:10:56

标签: javascript javascript-events popup firefox-addon popupwindow

有一个网站随机在其网站上显示一些活动弹出窗口。如果在Firefox等网站上显示弹出窗口时会通知用户,这将非常有用。可以借助javascript或任何附加组件等进行操作吗? 提前谢谢。

1 个答案:

答案 0 :(得分: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中,你可以看到什么是开窗器,如果它是那个网站,那么关闭那个窗口。