Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect users with Adblock and redirect javascript [duplicate]

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.

like image 574
Williams A. Avatar asked Aug 22 '13 18:08

Williams A.


2 Answers

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.

like image 28
Bolli Avatar answered Oct 07 '22 14:10

Bolli


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

like image 86
ataman Avatar answered Oct 07 '22 13:10

ataman