Skip to main content
Category:

Example How to detect Adblock on my website.

Most ads are dynamically loaded in javascript. I just used the onerror event to detect whether the ad script could be loaded or not. Seems to work.

Example with GoogleAds:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" onerror="showPopup();"></script>

<script>

function showPopup() {

  alert( 'Adblock detected on my website!' );

}

</script>

This can be used on other elements as well to see if an ad blocker is blocking the content. This method can produce false positives if the remote elements doesn't exist or cannot be reached.

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook