#jQueryTips: How to detect #AdBlock using #jQuery?


Updated May 8, 2016 ‚óŹ 1,159 views

AdBlock is a very useful plugin if you visit a site with a lot of annoying pop-up ads. But let's be honest, AdBlock is robbing a lot web content authors of their due income. How do you expect people to write content if they are not making money?

If you own a website, here's how you detect if a visitor has AdBlock enabled using jQuery:

$(document).ready(function(){
    if ($('#advertisement').height() == 0) {
        window.location = 'http://www.yoursite.com/AdblockNotice.html';
    }
});

What the above jQuery line of code does is basically detect whether the visitor has AdBlock plugin enabled. Then it redirects the user to a target page with a notice. You can tell the visitor to disable AdBlock in order to view your content.

0 Comments




Our Terms of Use and Privacy Policy have changed.
By continuing to use this site, you are agreeing to the new Privacy Policy and Terms of Use.