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?
They're utilizing the fact that Google's ad code creates an iframe with the id "iframe". So as long as you don't already have something on your page with that ID, this'd work for you too.
timing's
answer is nice thinked but no more working, so I have updated the name of the js file to 'adsense' from 'ads' and it is working back like a charm!Here is the code, maybe this wil help someone:
In the Js file put just this line:
var adblockDetecter = true;
Run this with adblock on and Paste this in your page-footer before the close of the
</body>
tag on your page.No need for timeouts and DOM sniffing. Simply attempt to load a script from popular ad networks, and see if the ad blocker intercepted the HTTP request.
<body>
tag at the top of your page:eg:
<body style="visibility: hidden !important;">
And add the following DIV tag immediately following your opening
<body>
tagDespite the age of this question, I recently found it very useful and therefore can only assume there are others still viewing it. After looking here and elsewhere I surmised that the main three client side checks for indirectly detecting an ad blocker were to check for blocked
div
/img
, blockediframe
s and blocked resources (javascript files).Maybe it's over the top or paranoid but it covers for ad blocking systems that block only one or two out of the selection and therefore may not have been covered had you only done the one check.
On the page your are running the checks add: (I am using jQuery)
and add the following anywhere else on the page:
I used a div with a bait name as well as an externally hosted image with the text "Advert" and in dimensions used by AdSense (thanks to placehold.it!).
In
advertisement.js
you should append something to the document which we can check for later. Although it seems like you're doing the same as before, you are actually checking for the file (advertisement.js
) itself being loaded, not the output.And then the ad blocker detection script which combines everything
When the document is ready, i.e. the markup is loaded, we add the iframe to the document also. Then, when the window is loaded, i.e. the content incl. images etc. is loaded, we check:
advertimsent.js
was not blocked.And the styles:
Hope this helps