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?
the safe way is to wrap your ads inside
<div>
and check the heightit work with adblock plus and bluehell firewall.
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.bottom-ad
class:<div class="bottom-ad" style="width: 1px; height: 1px;">HI</div>
$('.bottom-ad').css('display') == "none"
or even better by using$('.bottom-ad').is(':visible')
If value is
true
, then AdBlocker is active.http://thepcspy.com/read/how_to_block_adblock/
With jQuery:
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 thatdisplay: none
is also checked: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:Which will give you an array of ad elements which are "invisible" (with any being greater than
0
being a problem, in theory).