javascript - 阻止弹出窗口的脚本

标签 javascript jquery greasemonkey adblock

AdBlock 有时无法阻止弹出窗口,因此我想使用 Greasemonkey 使用 jQuery 编写自己的弹出窗口阻止程序。

有什么方法可以拦截点击并检测它是否会打开弹出窗口?

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

我可以用什么替换 /* $(this) 将打开一个弹出窗口 */ ?

最佳答案

如何使用 javascript 打开弹出窗口?

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

因此理论上您可以重写 window.open 函数来执行其他操作而不是打开弹出窗口。

window.open = null;

但是,如果 window.open 在被调用时为 undefined,它可能会破坏页面脚本。 因此,我认为最好的方法是:

window.open = function(){
   return;
}

我没有测试过这段代码,但正如我所说,理论上它应该可以工作。

关于javascript - 阻止弹出窗口的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8428272/

相关文章:

javascript - 类型错误 : Attempting to change configurable attribute of unconfigurable property of iframe's src

javascript - Appcelerator:将自定义(动态) View 添加到按钮单击创建卡上的 ScrollView

javascript - 使用javascript保存XHR文件

youtube - Greasemonkey脚本测试url和添加参数

firefox - 使用 Greasemonkey 在 Firefox 中取消页面前进/后退热键

javascript - 在 vue.js 中创建数组和多个文本输入之间的双向绑定(bind)

javascript - 如何停止 dragend 在拖放中的默认行为?

jquery - 如何定位滚动到 jquery 对话框的底部?

jquery - 使用 $(this) 在另一个 div 中选择一个 div

javascript - 如何使用event.target.matches匹配div元素