-1

I was updating my personnel website and after installing adBlock under Chrome i noticed some disfunctionning. I found that adBlock blocked some resources from my website like twitter-timeline script and linkedin.pnp image. I disable adBlock everything come back normal. Is there some Javascript code to know when a browser has a blocking extension and ask the user to disable it ?

Thanks

velocity
  • 1,630
  • 21
  • 24
  • Most sites have content that's normally hidden by the ad, so that when the ad is blocked, the user sees the content. e.g.: "We see you have AdBlock installed. We need revenue from ads to keep this site running" in a div that is the exact size and shape of the ad, but underneath the container that the ad is in. – RevanProdigalKnight Aug 20 '14 at 13:54

1 Answers1

1

First, you have to include a JavaScript file with the name of advertisement.js. Due to AdBlock Plus' filtering rules, this file is automatically blocked. Thus we can use this file to do some stuff that we can test against later to see if the user is using an adblocker or not.

<script type="text/javascript" src="advertisement.js"></script>

The contents of which are:

document.write('<div id="tester">an advertisement</div>');

The file writes an element to the page that we will test for later. This element is made invisible by a CSS rule:

#tester {
    display:none;

Now we use another piece of JavaScript at the location that we want the message to be displayed. This tests for the presence of the "tester" div we created earlier. If it's there, it means that ABP has not blocked our advertisement.js file and everything is good. If it's not there, it means that some sort of software blocked advertisment.js, and so we can write a special message to the page.

<script type="text/javascript">
if (document.getElementById("tester") != undefined)
{
    document.write('<p class="yes">No <strong>AdBlock Plus</strong> detected! Thanks for truly supporting our site.</p>');
}
else
{
    document.write('<p class="no">We\'ve detected that you\'re using <strong>AdBlock Plus</strong> or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising. To read more about why you should disable ABP, please <a href="#">click here</a>.<!-- end .content --></p>');
}
</script>

Here is the source of the answer.

Romo Daneghyan
  • 2,099
  • 3
  • 18
  • 23