StopBlock

So, the debate has raged on whether Ad-Block is ethical or moral or whatever word you would like to use to describe it. Regardless of your personal opinion, it has given some publishers so much angst that they have chosen to block all Firefox users (Why Firefox is Blocked) because of an inability to exclude visitors using the Ad-Block extension for Firefox. Well, suffice to say, there is a fairly simple bit of code that can be used to determine if a person is blocking advertisements on your site.

The Ad-Block extension not only blocks ads, it hides them. This means that the space previously consumed by an advertisement will disappear. So, the simple solution is two put two elements, in my case 1px by 1px images, above and below the advertisement. I then use javascript to determine their Top Offset (the distance between the element and the top of the page). If that distance is less than the height of my advertisement, I know that the user is blocking ads. The best part about this filter is that it would work for future technologies as well – unless of course they block javascript on your page altogether.

(1) First, copy and paste this into the header of your page:

<script> function stopBlock(topObjId,bottomObjId,estHeight) { var topObj = document.getElementById(topObjId); var bottomObj = document.getElementById(bottomObj); var toptop = 0; if (topObj.offsetParent) { toptop = topObj.offsetTop while (topObj = topObj.offsetParent) { toptop += topObj.offsetTop } } if (bottomObj.offsetParent) { bottomtop = bottomObj.offsetTop while (bottomObj = bottomObj.offsetParent) { bottomtop += bottomObj.offsetTop } } var buffer = 15; var loc = 'http://google.com/search?q=ad+blocking+immoral'; var distance = toptop - bottomtop; distance += buffer; if(distance > estHeight) { alert('This Site Does Not Allow Ad-Blocking.'); location.href=loc; } } </script>

(2) Second, assuming your advertisement is 500 pixels tall, copy and paste this into the bottom of your page:

<script>stopBlock('startAd','endAd',500);</script>

(3) Third, paste this code directly above your advertisement

<img src='http://thegooglecache.com/t.gif' height='1' width='1' id='startAd' /> <br style='line-height:1px;clear:both;' />

(4) Fourth, paste this code directly below your advertisement

<img src='http://thegooglecache.com/t.gif' height='1' width='1' id='endAd' />

(5) Fifth, if your nice, paste this code somewhere

Page protected by <a href='http://www.thegooglecache.com/'>stopBlock</a>

No tags for this post.