AdBlock有时无法阻止弹出窗口,因此我想使用Greasemonkey和jQuery编写自己的弹出窗口拦截器。
是否有一种方法可以拦截点击事件并检测是否要打开弹出窗口?
$('.popupLauncher').each(function(){
if( /* $(this) will open a popup */ ){
return false;
}
});
我该用什么替换
/* $(this) will open a popup */
?AdBlock有时无法阻止弹出窗口,因此我想使用Greasemonkey和jQuery编写自己的弹出窗口拦截器。
是否有一种方法可以拦截点击事件并检测是否要打开弹出窗口?
$('.popupLauncher').each(function(){
if( /* $(this) will open a popup */ ){
return false;
}
});
/* $(this) will open a popup */
?如何使用JavaScript打开弹出窗口?
window.open(url, etc, etc, etc);
理论上,您可以重写window.open
函数以执行其他操作而不是打开弹出窗口。
window.open = null;
然而,如果在调用时window.open
未定义,则可能会破坏页面脚本。
因此,我认为最好的方法是:
window.open = function(){
return;
}
我还没有测试过这段代码,但是理论上应该可以工作。
<a href="..." target="_window">
或类似的方式打开,不是吗? - user1046334return;
以使代码更短(效果相同)。 - user1046334
if ($(this.).attr("onclick").indexOf('open') !=-1)
在某些情况下可能有效。将正则表达式添加到广告拦截器中将需要更少的时间。 - mplungjan