5

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.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Williams A.
  • 683
  • 1
  • 8
  • 22
  • It depends on how you produce your ads. What API do you use? – Logan Murphy Aug 22 '13 at 18:09
  • 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 wan't to detect if uses Adblock and tell these users to disable it. Thanks! – Williams A. Aug 22 '13 at 18:13
  • What are you using to develop said game, flash? – Seth Aug 22 '13 at 18:15
  • Correct, It's a flash game. – Williams A. Aug 22 '13 at 18:16
  • 1
    As there are no actual advertisements in play here, it would seem a better option would be to contact Adblock and inform them of the problem. They should be able to either whitelist the game, or explain why it was blocked. – bshacklett May 11 '14 at 15:15

2 Answers2

4

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

ataman
  • 2,644
  • 17
  • 22
  • Thanks but, 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 wan't to detect if uses Adblock and tell these users to disable it. Thanks! – Williams A. Aug 22 '13 at 18:15
  • $('#yourAdContainer').is(':visible') also works – Seth Aug 22 '13 at 18:15
  • I don't have ads, thats the problem. – Williams A. Aug 22 '13 at 18:19
  • It doesn't work, ¿Why? – Williams A. Aug 22 '13 at 18:32
  • Check out fiddle example. Works for me in chrome and FF with adblock plus. http://jsfiddle.net/GhUHD/2/ – ataman Aug 22 '13 at 18:51
  • Sorry, but this doesn't show any alert. ¿It's supose to have a special configuration? – Williams A. Aug 22 '13 at 18:58
  • It may depend of Adblock Plus subscription. My subscription is https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt . Actually, I took `#advblock` id from that list. You may have another subscription, or maybe, you have another Adblock? – ataman Aug 22 '13 at 19:10
  • Yes thats my adblock, i will check thanks. – Williams A. Aug 22 '13 at 19:58
  • I am not sure if this would work now, since adblock seems to blocks all DOM ready, onload, and related functions. This is in reference to Adblock extension. – Ankit Rustagi Feb 13 '14 at 10:09
1

Check if your div containing the game has a "ad like" class or id name.

Adblocks filters are big, so if you use class or id names that has

ad or advertising or something that could hint it was an ad, changes are it will get blocked because of existing filters. This has happened to me. Try renaming them.

Bolli
  • 4,974
  • 6
  • 31
  • 47