I'm working on a basic Adblock detection script, and I've come up with something that seems like it should work. Upon creating an element on the page with the ID of #adblock_detection_image
in Chrome with Adblock Plus, running $('#adblock_detection_image').css('display')
gives me the value none
and running $('#adblock_detection_image').css('visibility')
gives me the value hidden
. When running these on a browser with no Adblocker, I get inline
and visible
instead, as one might expect.
Finding this, I went ahead and attempted to craft a solution. The issue - however - is that the code that should trigger when an adblocker is detected simple doesn't trigger. The code snippet is shown below.
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');
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…