Search code examples
javascripthttp-redirectwebblockadblock

How to detect users with Adblock and redirect javascript


I have been searching things about how to detect an ad-block and I found some things but none of them worked. How can I detect an ad-block in my web site and redirect the users? For example:

I have a ad-block, and go to www.lol.com it should redirects me to www.lol.com/adblock.php.

Edit

I just don't have ads, I'm developing a online game but users that have Adblock for some weird reason blocks the game. I just want to detect whether a user uses Adblock and tell these users to disable it.


Solution

  • If AdBlock hides your ads, you can just check if height of your ad containers is zero:

    $(function() {
      if (!$("#yourAdContainer").height()) {
        window.location.href = "www.lol.com/adblock.php";
      }
    });
    

    UPDATE:

    If you have no ads, you can create invisible block with id, known by adblock, of fixed height on page load, and check it's height. Example from my project:

    $(document.body).append('<div id="advblock" style="position: absolute; opacity: 1; top: 0; left: 0;">hh</div>');
    setTimeout(function() {
      if (!$('#advblock').height()) {
        window.location.href = "www.lol.com/adblock.php";
      }
      $("#advblock").remove();
    }, 1);
    

    Fiddle