Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

javascript - Problems with Adblock detecting

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

perhaps , an adblocker remove the elemet contained the ads , in there "#Ad-one",so when you access the css of this element by jq ,in reality you access to an unavilable element was removed from html source earlier.isnt it true?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...