Adblock Detection Script

Last Updated:
As a publisher, you may want to measure what percentage of your visitors are using an Adblock, so you can take action accordingly. For example, you can show an "Adblock Detected" warning message and ask them to disable their ad blocker in order to continue. Or you can deny access to your web pages completely using a paywall. To do so, you need an Adblock Detection Script.

AdGlare Ad Server is using the script here below, which is available for you to use free of charge. It works by creating a DIV that is likely to be hidden by ad blockers, and then verifying if that DIV was indeed hidden. The presence of an ad blocker has been successfully detected in these web browsers at the time of writing (June 2018): Chrome, Firefox, Safari and Internet Explorer 8+.
Ad Block Detection Script
Fishing for AdBlock using CSS class baits.

Advantages of this script

AdGlare's Adblock detector has a few advantages over more sophisticated alternatives:
  • It uses class names as a bait (no HTTP requests).
  • Ad block detection is incredibly fast.
  • With only a few lines of code, it's very small.
  • Simple function returning a true/false boolean.

JavaScript: Adblock Detector Code

Copy/paste this code to a test page to see how it works in your browser. You will see a message box returning true or false indicating if you have an ad blocker installed or not.
<script> /* Author: AdGlare Ad Server ( */ function hasAdblock() { var a = document.createElement('div'); a.innerHTML = '&nbsp;'; a.className = 'adsbox pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads adglare-ad-server text-ad-links'; = 'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;'; var r = false; try { document.body.appendChild(a); var e = document.getElementsByClassName('adsbox')[0]; if(e.offsetHeight === 0 || e.clientHeight === 0) r = true; if(window.getComputedStyle !== undefined) { var tmp = window.getComputedStyle(e, null); if(tmp && (tmp.getPropertyValue('display') == 'none' || tmp.getPropertyValue('visibility') == 'hidden')) r = true; } document.body.removeChild(a); } catch (e) {} return r; } alert('Has AdBlock: ' + hasAdblock()); </script>

Minimized Version

Here's a minimized version of the above script, ready to be added to your web page's global .js file.

Download from GitHub

You can find this code also on our GitHub page. See


As a publisher, you should at least measure Adblock usage on your website. If only a small portion of your traffic cannot be monetized due to ad blockers, you can consider denying access to those visitors. If usage is high, alternative ad serving methods that circumvent ad blockers are worth considering, like Native Ads. Publishers monetizing video content can switch to to get around ad blockers.

External Resources

Share This

This article stays online on the following URL: