AdBlock Plus detection demonstration

AdBlock Plus is a Firefox extension that blocks many, many types of advertising. While conceived with good intentions, many websites claim that ABP and other adblocking programs are becoming a serious problem and cutting off their revenue stream.

This is a simple demonstration that detects whether the visitor to this page has AdBlockPlus enabled or not.

Demo

Install the AdBlock Plus Firefox extension, and then toggle it on and off on this domain to see the difference.

Here's how it works: First, we 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('

No AdBlock Plus detected! Thanks for truly supporting our site.

'); } else { document.write('

We\'ve detected that you\'re using AdBlock Plus 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 click here.

'); } </script>

View the source for more specific information. I hacked this together in like 10 minutes. You can probably do better, but it's just a demonstration of how it's quite easy to detect ad-blocking software and act on it.