Header Image In my previous post, I talked about how 68.8% of my desktop visitors are using Adblock and how the iOS 9 changes will impact me as well.

Someone recently read my post, and asked if there was a way to detect these users using Adblock. One of the issues with using this however, is that people may just skip over your site instead of disabling the Adblocker on your site. I want people to be able to read my content, which is why that’s what I choose to do. For those of you who still want to do something about this however, here’s the solution:

setTimeout(function() {
        var adsbygoogle = document.getElementsByClassName('adsbygoogle');
        if (adsbygoogle && adsbygoogle.length > 0 && adsbygoogle[0].childNodes.length == 0) {
                console.log('Please turn off adblock!');
        }
}, 1000);

This is made to work with Google Adsense, but if you show me a site with another ad supplier, I can modify that to work with them as well. This snippet works, because none of the Adblockers I could find (uBlock, Adblock, Adblock Plus) actually removed the ad container. Instead, they remove the ad container’s children. So the snippet first checks if there’s an ad on the page, then checks if it has child nodes. If it doesn’t, hurrah. You can now ban the adblocker from your site, or whatever feels appropriate.

If you want proof it’s working, this exact snippet is running on this site. Just turn off your adblocker (and keep it off if you choose) and check the console. No message! But if you turn it on, the console will nicely ask you to turn it off.