There is no 100% technique, but there are some recommended:
Checking the size of an element
function detectAddNotLoaded() {
if ($('.foo_dd').height() == 0) {
// Aqui vc toma a decisão. Mostrar um aviso, redirecionar, etc...
}
}
$(document).ready(function(){
detectAddNotLoaded();
});
<div class="foo_dd"><script>
//aqui deve mostrar um banner, mas o adblock bloqueia.
//A ideia é verificar a altura. Se for ZERO, possivelmente não foi carregado devido ao adblock
</script></div>
<div class="foo_dd"><script>
//aqui deve mostrar um outro banner
</script></div>
Against: A user without Adblock enters the page and the banners may not load for any failure or may take time to load.
The advantage over the next example is that it becomes more consistent against more sophisticated blockers that do not block files by naming (ads.js, Advertisement.js, etc)
Loading a blocked file
The technique is to load a url whose name is blocked by the blockers.
The logic is, the ajax request will fail because the blocker will prevent you from accessing "/js/ads.js".
$.ajax({
url: "/js/ads.js",
dataType: "script"
})
.fail(function () {
// Aqui vc toma a decisão. Mostrar um aviso, redirecionar, etc...
});
The ads.js file may be empty.
Usually blockers try to block everything that is named as ads.js, Advertisement.js, and related names. So, the logic is this.
Against: The ajax request may fail for N reasons. Think of the user who has no blocker and then happen ajax fails.
Considerations
For both examples, points against present a small probability of combinations.
The above examples are not definitive solutions, nor do they have this claim. Be aware that there are other ways to resolve (read "get as close to desirable as possible"). Blockers change algorithms periodically to fit the market as advertisements also fit the market and seek to protect themselves from blockers. It is a constant "war".
Finally, which decision to make depends on each case.
Evaluate the pros and cons for your case.
Note: this is just an opinion, and it has nothing to do with the technical content of the question, OK? : ) I find it curious how this ad scheme works. The developer forces an ad down the throat of the user because it needs the money, and the user looks for ways to block them because they are simply boring. Then the developer looks for ways to block the lock, and eventually the user will look for ways to block the lock... rs Surely there are better ways to earn your deserved money. If users are blocking their ads, there is something very wrong with them.
– Luiz Vieira
@Luizvieira, I don’t work with developing open-source solutions that need ads, so I’m not sure how this world turns. But the user will not use Adblock because of the unique and exclusive reason of my ads, he is using by tired of ads all over the web sites that abuse this feature, so regardless of the way my ads are presented, they will be blocked!
– Fernando Leal
@Fernando Yes, of course, but is that my placement was generic and I wanted to say that this advertising model (via popup or before presenting the content) is simply bizarre. There are better ways to display ads, but this is a discussion pro [chat] and not to be done here. :)
– Luiz Vieira
@Fernando just an opinionated note, is the following I have a site, the ads are not invasive and do not disturb, but the user has already passed some similar experience on other sites, ready it blocks all sites and I am harmed, so I see so, I put an anti-ab on my website, the guy is obliged to put me on Whitelist and after browsing a little he realizes that the advertisements on my site are not abusive... Another site does the same as me, but the advertisements are abusive, so simply the user will not return there. I think at this point the anti-ab is great...
– Guilherme Nascimento
@Fernando ... That is if the guy uses an anti-ad and has a site "pig" he will end up paying for it. I am totally in favor of advertisements, as long as they do not disrupt navigation or invade the screen and/ or basic features.
– Guilherme Nascimento
@Luizvieira read my comments above.
– Guilherme Nascimento
@Guilhermenascimento Okay, but if the advertisements on a website are not abusive, why the hell would he need an anti-blockade? Perhaps our concept of "abusive" is not the same. : ) In any event, I stress that this matter should not be discussed here in the comments.
– Luiz Vieira
@Luizvieira see, I provide a free content, my only source of income to maintain the site are ads, detect such blocks is essential for me to maintain my business, do not agree?
– Guilherme Nascimento
I agree with @Fernandoleal. Much as Luizvieira’s opinion makes sense Adblock is installed globally in the browser for all sites. To work in a way that caters to developers who display ads in a way that doesn’t irritate the user, the ideal would be for Adblock to ask if the user wants to block ads from the site they are visiting.
– Andre