Detect AdBlock with JQuery | andi setiawan's blog

Some bloggers like me maybe so pissed to know that our ad revenue is decreasing dramatically after introduction of Ad blocking plugin (like AdBlock/Adblock Plus, etc). But lucky I found a way to ask the audience to disable the plugin when detected. In this case, I used jQuery to detect adBlock.

I used JQuery to detect ad blocking plugin for my other website. Here’s the code I used:

First, I put my ads inside a DIV, and name it “yourcode”.

<div id="yourcode"><!-- your ad code ---></div>

And put this code just below it:
<script type="text/javascript">
     jQuery(document).ready(function(){
          if (jQuery('#yourcode').height() == 0) {
               alert('ADBLOCK IS ACTIVE!');
          }
     });
</script>

That’s the simple detection method. But, you can change the code above as per your need.

For example, I edited the code in andiim3.com to hide some contents (download links) when the code detected adBlock and show a dialog asking audience to disable the ad blocking plugin.

I put extra code just after “alert()” to trigger some action after audience clicked the “OK” button.

Need help? Leave a comment below..


Posted in programming, Tips n Trik | Tagged , , , , |

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: