How to detect Adblock on my website?

2019-01-01 07:23发布

I would like to be able to detect if the user is using adblocking software when they visit my website. If they are using it, I want to display a message asking them to turn it off in order to support the project, like this website does.

If you enter to that site and your browser has some kind of adblock software enabled, then the site instead of showing the actual ads shows a little banner telling the users that the ad revenue is used for hosting the project and they should consider turning Adblock off.

I want to do that on my website, I'm using adsense ads on it, How can I do that?

45条回答
姐姐魅力值爆表
2楼-- · 2019-01-01 08:25
if||Math|function|window||length|return|font||body|random
查看更多
十年一品温如言
3楼-- · 2019-01-01 08:25
visible|YueVFIKLqs|640|ZmF2aWNvbi5pY28|innerWidth|YWR2ZXJ0aXNpbmcuYW9sLmNvbQ|an|using|re|YWdvZGEubmV0L2Jhbm5lcnM|you|like|It|looks|adb8ff|Welcome|YS5saXZlc3BvcnRtZWRpYS5ldQ|FFFFFF|c3BvbnNvcmVkX2xpbms|okay|EEEEEE|777777|That|YWQuZm94bmV0d29ya3MuY29t|Who|understand|styleSheets|kcolbdakcolb|moc|in|me|Let|clear|YWRuLmViYXkuY29t|Z29vZ2xlX2Fk|my|disabled|have|awesome|doesn|YWQubWFpbC5ydQ|anVpY3lhZHMuY29t|site|making|keep|can|script|we|income|advertising|without|But|b3V0YnJhaW4tcGFpZA|QWRCb3gxNjA|YWRzZW5zZQ|191|QWQzMDB4MjUw|QWQzMDB4MTQ1|YWQtY29udGFpbmVyLTI|YWQtY29udGFpbmVyLTE|YWQtY29udGFpbmVy|YWQtZm9vdGVy|YWQtbGI|YWQtbGFiZWw|YWQtaW5uZXI|YWQtaW1n|YWQtaGVhZGVy|YWQtZnJhbWU|YWRCYW5uZXJXcmFw|YWQtbGVmdA|c1|QWRBcmVh|192|2048|127|z0|Za|encode|setTimeout|null|frameElement|VBTxktzQKI|event|190|277|295|QWQ3Mjh4OTA|QWRGcmFtZTE|cG9wdXBhZA|QWREaXY|YWRzbG90|YmFubmVyaWQ|YWRzZXJ2ZXI|YWRfY2hhbm5lbA|IGFkX2JveA|YmFubmVyYWQ|YWRBZA|YWRiYW5uZXI|YWRCYW5uZXI|YmFubmVyX2Fk|YWRUZWFzZXI|Z2xpbmtzd3JhcHBlcg|QWRDb250YWluZXI|cHJvbW90ZS5wYWlyLmNvbQ|QWRJbWFnZQ|QWRGcmFtZTI|QWRzX2dvb2dsZV8wMw|QWRGcmFtZTM|QWRGcmFtZTQ|QWRMYXllcjE|QWRMYXllcjI|QWRzX2dvb2dsZV8wMQ|QWRzX2dvb2dsZV8wMg|QWRzX2dvb2dsZV8wNA|RGl2QWRD|RGl2QWQ|RGl2QWQx|RGl2QWQy|RGl2QWQz|RGl2QWRB|RGl2QWRC|Y2FzLmNsaWNrYWJpbGl0eS5jb20||YWQtbGFyZ2UucG5n|YWRzLnlhaG9vLmNvbQ|adblock|radius|background|join|reverse|split|click|40px|160px|FILLVECTID2|FILLVECTID1|plugin|black|120|5pt|YWRzLnp5bmdhLmNvbQ|blockadblock|http|9999|innerHeight|clearInterval|head|onclick|css|stylesheet|minWidth|minHeight|link|rgba|solid|1px|hr|500|200|999|45px|35px|18pt|onmouseover|screen|8px|fff|24px|14px|boxShadow|onmouseout|borderRadius|marginRight|12px|16pt|normal|line|Black|Arial|rel|com|d2lkZV9za3lzY3JhcGVyLmpwZw|insertBefore|Ly9hZHMudHdpdHRlci5jb20vZmF2aWNvbi5pY28||bGFyZ2VfYmFubmVyLmdpZg|YWRjbGllbnQtMDAyMTQ3LWhvc3QxLWJhbm5lci1hZC5qcGc
查看更多
何处买醉
4楼-- · 2019-01-01 08:27

the safe way is to wrap your ads inside <div> and check the height

<div id="check-ab">
/* your ads code */
</div>

setTimeout(function(){
  if(document.getElementById("check-ab").offsetHeight === 0){
    console.log("ads blocked");
  }
  else{
    console.log("ads running");
  }
}, 100);

it work with adblock plus and bluehell firewall.

查看更多
还给你的自由
5楼-- · 2019-01-01 08:27
步步皆殇っ
6楼-- · 2019-01-01 08:28

This approach I use on my site, maybe you will find it helpful. In my opinion, it's the simpliest solution.

AdBlocker blocks specific classes and html elements, by inspecting these selectors of any blocked ads in developer console (they are all listed) you can see which elements will be always blocked.

E.g. just inspect this question page on stackoverflow and you will see bunch of blocked ads.

For example, any element with bottom-ad class is automatically blocked.

  1. I created a non-empty div element with bottom-ad class: <div class="bottom-ad" style="width: 1px; height: 1px;">HI</div>
  2. After page loads just check if this element is hidden. I used jQuery, but feel free to use javascript: $('.bottom-ad').css('display') == "none" or even better by using $('.bottom-ad').is(':visible')

If value is true, then AdBlocker is active.

查看更多
千与千寻千般痛.
7楼-- · 2019-01-01 08:29

http://thepcspy.com/read/how_to_block_adblock/

With jQuery:

function blockAdblockUser() {
    if ($('.myTestAd').height() == 0) {
        window.location = 'http://example.com/AdblockNotice.html';
    }
}

$(document).ready(function(){
    blockAdblockUser();
});

Of course, you would need to have a landing page for AdblockNotice.html, and the .myTestAd class needs to reflect your actual ad containers. But this should work.

EDIT

As TD_Nijboer recommends, a better way is to use the :hidden (or :visible, as I use below) selector so that display: none is also checked:

function blockAdblockUser() {
    if ($('.myTestAd').filter(':visible').length == 0) {
        // All are hidden, or "not visible", so:
        // Redirect, show dialog, do something...
    } else if ($('.myTestAd').filter(':hidden').length > 0) {
        // Maybe a different error if only some are hidden?
        // Redirect, show dialog, do something...
    }
}

Of course, both of these could be combined into one if block if desired.

Note that visibility: hidden will not be captured by either as well (where the layout space stays, but the ad is not visible). To check that, another filter can be used:

$('.myTestAd').filter(function fi(){
    return $(this).css('visibility') == 'hidden';
})

Which will give you an array of ad elements which are "invisible" (with any being greater than 0 being a problem, in theory).

查看更多
登录 后发表回答