Question: I would like to be able to detect if the user is using adblocking software when they visit my website. If they are using it, I want to display a message asking them to turn it off in order to support the project, like [this website](http://www.playonlinux.com/en/) does.

If you enter to that site and your browser has some kind of adblock software enabled, then the site instead of showing the actual ads shows a little banner telling the users that the ad revenue is used for hosting the project and they should consider turning Adblock off.

I want to do that on my website, I'm using adsense ads on it, How can I do that?

Answer: 
<http://thepcspy.com/read/how_to_block_adblock/>

With jQuery:

```
function blockAdblockUser() {
    if ($('.myTestAd').height() == 0) {
        window.location = 'http://example.com/AdblockNotice.html';
    }
}

$(document).ready(function(){
    blockAdblockUser();
});

```

Of course, you would need to have a landing page for AdblockNotice.html, and the .myTestAd class needs to reflect your actual ad containers. But this should work.

**EDIT**

As TD\_Nijboer recommends, a better way is to use the `:hidden` (or `:visible`, as I use below) selector so that `display: none` is also checked:

```
function blockAdblockUser() {
    if ($('.myTestAd').filter(':visible').length == 0) {
        // All are hidden, or "not visible", so:
        // Redirect, show dialog, do something...
    } else if ($('.myTestAd').filter(':hidden').length > 0) {
        // Maybe a different error if only some are hidden?
        // Redirect, show dialog, do something...
    }
}

```

Of course, both of these could be combined into one `if` block if desired.

Note that `visibility: hidden` will not be captured by either as well (where the layout space stays, but the ad is not visible). To check that, another filter can be used:

```
$('.myTestAd').filter(function fi(){
    return $(this).css('visibility') == 'hidden';
})

```

Which will give you an array of ad elements which are "invisible" (with any being greater than `0` being a problem, in theory).
My easiest solution with jquery is:

```
$.ajax({
    url: "/scripts/advertisement.js", // this is just an empty js file
    dataType: "script"
}).fail(function () {
    // redirect or display message here
});

```

advertisement.js just contains nothing. When somebody uses adblock, it fails and the function gets called.