Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to block popups

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 */ ?

like image 759
JSninja Avatar asked Nov 20 '25 17:11

JSninja


1 Answers

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.

like image 131
Pierre Avatar answered Nov 22 '25 09:11

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!