我正在开发一个基本的 Adblock 检测脚本,并且我想出了一些看起来应该可以工作的东西。#adblock_detection_image
在带有 Adblock Plus 的 Chrome 中创建 ID 为的页面上的元素时, running$('#adblock_detection_image').css('display')
给了我 valuenone
并且 running$('#adblock_detection_image').css('visibility')
给了我 value hidden
。当在没有 Adblocker 的浏览器上运行这些时,我得到了inline
,visible
相反,正如人们所期望的那样。
发现这一点,我继续尝试制定解决方案。但是,问题是当检测到简单的广告拦截器时应该触发的代码不会触发。代码片段如下所示。
function isUsingAdblocker(classOfAd)
{
if(parseInt($(classOfAd).css('height')) <= 0)
{
return true;
}
else
{
$('body').append('<img id="adblock_detection_image" src="/textlink-ads-banner-advert-service.jpg" style="width: 0; height: 10px; position: relative; top: -1000px; left: -1000px;"/>');
if($('#adblock_detection_image').css('display') != 'inline')
{
return true;
}
else if($('#adblock_detection_image').css('visibility') != 'visible')
{
return true;
}
else
{
return false;
}
}
}
$(document).ready(function(){
if(isUsingAdblocker('#Ad-One')){
$('#Ad-One').html('<em>Please</em> disable your ad-blocking software to help support this website.<br/><span>(It\'s our primary source of income!)');
$('#Ad-One').css('height', '90px');
}
});