[email protected]
Twitter
LinkedIn
YouTube
GitHub
  • Services
  • Blog
  • Repositories
  • GitHub
  • Resume
  • Contact
Product was added to your cart

Cart

Detecting AdBlock with jQuery or JavaScript

August 13, 2015Front-End, Tricksjfadev

Recently a large number of users use browser extensions that block advertising, the most known is AdBlock Plus. If our website is financed thanks to the publicity this can be a problem. In this case we can use JavaScript to detect if AdBlock or another similar plugin is blocking our advertising.

A cunning may be placing the script of advertising within a div and check if your height is greater to 0.

Html:

<div class="myAd">
    <!-- Ad code -->
</div>

JQuery:

jQuery(document).ready(function() {
    if (jQuery('.myAd').height() == 0) {
        // AdBlock active
    }
});

Js:

var interval = setInterval(function() {
    if (document.readyState === 'complete') {
        clearInterval(interval);
        if (document.getElementsByClassName('myAd')[0].clientHeight > 0) {
            // AdBlock active
        }
    }    
}, 100);

Another cunning can be check for iframes since ads like AdSense use them.

jQuery:

if (jQuery('iframe').length > 0) {
    // AdBlock active
}

Js:

if (document.getElementsByTagName("iframe").item(0) == null) {
    // AdBlock active
}

: AdBlock, Ads, jQuery, JS, Web Developement

Services

  • Excel2chatGPT $10.00
  • Bot Tok $45.00
  • Fix bugs in your PHP Symfony App $70.00 / hr
  • Fix bugs in your Wordpress Site $70.00 / hr
  • Tasks Automation using Node.js $70.00 / hr

Blog

  • How to Pay with a Bank Card on Cryptomus
  • Complete Beginner’s Guide to Bot Tok: Terminal Commands Explained
  • Top Site to Gain Views on TikTok
  • Jfa Whatsapp Chatbot
  • TikTok Bot

Explore

  • Free 10 Tiktok Likes
  • Free 2K TikTok Views
  • Free 100 TikTok Favorites
  • Free 300 TikTok Shares
  • Buy TikTok Views
  • Free 100 Instagram Likes
Twitter
LinkedIn
YouTube
GitHub

© 2013-2025 Jordi Fernandes Alves (@jfadev)