简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM