Jack
Jack

Reputation: 1

Catch popup window and notify user in Firefox

There is a web site that randomly shows up some campaign popup windows on their web site. It would be very useful if a user would be notified when a popup is shown up on that site in Firefox, etc. Can it be possible with the help of Javascript, or any add-on, etc.?

Upvotes: 1

Views: 168

Answers (1)

Noitidart
Noitidart

Reputation: 37238

Two options.

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

This is the nsiwindowmediator way:

/*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);

so now in the onOpenWindow, you can see what is the window opener, if it was that website, then close that window.

Upvotes: 1

Related Questions