Question

AdBlock sometimes fails to block popups, so using Greasemonkey I want to write my own popup blocker using jQuery.

Is there a way I can intercept the clicks and detect if it's going to open a popup?

$('.popupLauncher').each(function(){
    if( /* $(this) will open a popup */ ){
        return false;
    }
});

With what can I replace /* $(this) will open a popup */ ?

Was it helpful?

Solution

How do you open a popup using javascript ?

window.open(url, etc, etc, etc);

So in theory you can re-write the window.open function to do something else rather than opening a popup.

window.open = null;

However it might break the page scripts if window.open is undefined when being called. Therefore I think the best approach would be:

window.open = function(){
   return;
}

I haven't tested this code, but as i said, in theory it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top