Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[7] html - How to create even cell spacing within a

548k questions

547k answers

4 comments

86.3k users

...