Most websites are freely accessible, running costs are covered by advertisements. Over time a lot of webmasters have gone crazy by cluttering all their sites with ads, making it difficult to spot the interesting content. Articles are split up in multiple parts so that you have to click through several pages to read everything. By loading each page a new advertisement appears.

Smart programmers have developed a software called Adblock Plus. This plugin for the Firefox browser filters the majority of all ads. Internet Explorer users can install IE7Pro, Opera users can use the built-in functionality "urlfilter.ini".

Probably only a small number of people use ad-blocking software today, but this number will increase. Future browser generations might even have an active built-in ad-blocking functionality.

Consequently many webmasters will (or should) be concerned about how to finance their website in the future. With the script on this site you can show readers using ad-blocking software alternative content instead of filtered ads. For example:

  • PayPal donate button
  • Links to other websites
  • Images
  • An automatic redirect to another website (though it's possible, I don't recommend you to do that)

The script is split into three parts:

adframe.js

adblock = false;

"adframe.js" is recognised as advertisement by the majority of ad-blocking software. I have tested this behaviour with Adblock Plus (Filter subscriptions EasyList, Cédric and Dr.Evil), IE7Pro and Opera (list by Fanboy). (13/07/2008)

Update 23 Oct 2014: The Chrome extension "Adblock" doesn't recognize adframe.js as advertisement. Therefore you should move the file to the sub-foder "ad/adframe.js.

YourPage.html (ads)

<div class="a">Advertisement</div>
Put each advertisement in a div-container of class "a".

YourPage.html (end of file)

<script type="text/javascript">
<!--
	var adblock = true;
//-->
</script>
<script type="text/javascript" src="ad/adframe.js"></script>
<script type="text/javascript">
<!--
	if(adblock) {
		var allElements = document.getElementsByTagName('div');
		for (var i = 0; i < allElements.length; i++) {
			if (allElements[i].className == 'a') {
				allElements[i].innerHTML = 'alternative content';
			}
		}
	}
// http://detect-ad-blocking-software.webconrad.com/
//-->
</script>

</body>
</html>

You have to put these three Javascripts at the end of your file. The first Javascripts sets the variable "adblock" to "true", the second to "false" again (as long as no ad-blocking software is active). If the ad blocker prevents access to the file "adframe.js" the code after "if(adblock)" will be executed and the alternative content will be displayed.

In the example above all ads will be replaced by the same alternative content. If you have different ads in different formats on your site you can replace them individually as well.

YourPage.html (ads) - individual replacement

<div id="a1">Advertisement 1</div>
<div id="a2">Advertisement 2</div>
Put each advertisement in a div-container with an individual id.

YourPage.html (end of file) - individual replacement

<script type="text/javascript">
<!--
	var adblock = true;
//-->
</script>
<script type="text/javascript" src="ad/adframe.js"></script>
<script type="text/javascript">
<!--
	if(adblock) {
document.getElementById("a1").innerHTML = 'alternative content 1';
document.getElementById("a2").innerHTML = 'alternative content 2';
} // http://detect-ad-blocking-software.webconrad.com/ //--> </script> </body> </html>

Examples

Download

Note that most ad blockers only work online, not with locally opened files.

Book recommendation

If you either sell something online or you earn money with affiliate marketing there is one book that definitely is a must read! You'll find a ton of information on how to increase your conversion rate. If you currently earn 200 $ a month from online ads and you triple your conversion rate with the help of this book, you'll earn 600 $ with the same amount of visitors!

You Should Test That by Chris Goward | Price: US UK



Deutsche Version Deutsche VersionMore projectsDo YOU have wrist pain?Imprint