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.

28 Comments

  1. no one
    Aug 29, 2007

    You can turn off the hiding of the ad in adblock. turning off that option would render your fix useless.

  2. Dan
    Aug 29, 2007

    Ad-Block Plus has an option “Collapse blocked elements”. If this option is unchecked, I bet your Javascript fails. Try it.

  3. russ jones
    Aug 29, 2007

    Yes, it probably would fail. Although I do not really understand the purpose of hiding ads but leaving giant white spaces in their place… maybe to save a fraction of a seconds worth of download time?

  4. gfleischer
    Aug 29, 2007

    I tried to use the script, but there seemed to be some bugs that prevented it from working.

    Below is a diff of the changes I made. (If this doesn’t display well in the post, you can grab the source from the test page I threw up: http://pseudo-flaw.net/adblock/ ).

    — stopBlock.orig 2007-08-29 15:53:52.000000000 -0000
    +++ stopBlock.new 2007-08-29 15:53:07.000000000 -0000
    @@ -1,7 +1,7 @@
    function stopBlock(topObjId,bottomObjId,estHeight) {

    var topObj = document.getElementById(topObjId);
    – var bottomObj = document.getElementById(bottomObj);
    + var bottomObj = document.getElementById(bottomObjId);
    var toptop = 0;
    if (topObj.offsetParent) {
    toptop = topObj.offsetTop
    @@ -17,9 +17,9 @@
    }
    var buffer = 15;
    var loc = ‘http://google.com/search?q=ad+blocking+immoral’;
    – var distance = toptop – bottomtop;
    + var distance = bottomtop – toptop;
    distance += buffer;
    – if(distance > estHeight) {
    + if(distance

  5. Lucia
    Aug 29, 2007

    Could we replace the blankspace with a big blinking image? 🙂

  6. me
    Aug 29, 2007

    DEMO?

  7. Save Video
    Aug 29, 2007

    Yup it is flawed, don’t impose restrictions on the user like this. It’s bad form – I understand your problem, and every webmaster has this problem but don’t take it out on the user – they’re only doing what they can.

    It’s their computer, their bandwidth vs your content, and your profits. It’s a difficult argument for both sides, so for now don’t harass your visitors unless more then 80% are adblocking.

  8. Roma
    Sep 5, 2007

    I get javascript errors if I try to use your code..

  9. will
    Sep 17, 2007

    Even if this works, how long do you all think it will take for the Adblock plugin folks to create a workaround? My guess is about 2 weeks max.

  10. Paul S
    Oct 5, 2007

    I just use NoScript in combination with adblock….

  11. CyBrChRsT
    Jan 15, 2008

    same as the guy above =)
    U can fool some people but not all of us!
    Doesn’t hurt to run a proxy server as well.
    eh hem… squid on roids!

  12. Matt
    May 10, 2008

    So it is unethical to block ads but not adblockers?

  13. George E
    Sep 14, 2008

    So let me understand this, you WANT to infest people’s screen with dancing mortgage idiot ads and other stuff, it’s YOU who gets to decide what people will allow on their PC?!? And then you want to try to make it about ETHICS when you are trying to DISABLE something people have used to take back their internet experience?!? Oh and don’t worry, in case the AdBlock people didn’t have this figured out I sent them the link to this just to be sure!

  14. insertnamehere
    Nov 30, 2008

    add block is like switching channel on the tv during commercial. Is that morally wrong?

    And only (100% sure, its true!) ONLY RETARDS actually click those adds on purpose! And retards don’t know how to install add block. Case closed.

  15. Pedant
    Nov 8, 2009

    Err… your adblock test page loads fine once I’ve blocked (actually replaced, see add-art.org ) your ad, and doesn’t send me to google.

    Also, you spelled ‘you’re’ wrong.

  16. Me
    Nov 22, 2009

    I pay for broadband and comcast has ads all over there web mail so does aol if i am paying for servace wtf is the ads for GREED GREED and more Fuk1ng greed i have blocked all adds at my wingate and have firefox users blocking them and will block ads for the rest of my life you reedy basterDs

  17. Ad Blocking Lover
    Jul 9, 2010

    yeah, good luck getting around my HOSTS file ad blocking.

  18. Anon
    Jan 17, 2011

    I find it offencive that admins would block an entire user agent just because of one “unofficial” plug-in. Also, I would never buy a product based on a pop-up or advertisement. Besides, there is an agent switcher plugin which can spoof me as chrome/ie/iphone and bypass the whole issue.

  19. jonboy
    Feb 7, 2011

    For what it’s worth – most people who install adblock for FF also install the agent switcher – so they can appear to be any agent they wish.

    All you’ve done is remind people that they should also block javascript (which I recommend anyway).

    Good luck. You’ll need it. But you did bring it on yourselves you know, with your ad abuse (which was unethical, immoral, and for those paying for their internet connection by the Kbyte – theft). If you try to force feed a kid and they shut their mouths – didn’t you know that?

  20. admin
    Feb 17, 2011

    You guy’s still don’t get it. Your browser requests my HTML page, which has code in it that displays ads. At that point, your browser with a proper extension could say “this page has ads on it, do you want to proceed?”. Instead, your extension continues onto the page and blocks the ads. If you walk into my place of business and I tell you that it costs $1 to buy a coke, you can’t blame me for getting upset when you take the coke and walk out without paying. Your browser KNOWS there are ads on the page before it downloads them and before it displays them. You and the authors of ad-blocking software DECIDED to ignore that piece of information and skip instead to hiding the ads.

  21. Mike
    May 28, 2011

    Have you even considered the fact that people will not wait for the ads to load and just move on? Thats what I used to do. Adblock gets more people to look at your content. It should be content first. If I browse a trusted site, like amazon or npr, I turn off adblock. But you have to earn my trust first! Most sites load the ads before the rest of the page. Even google uses load time as a ranking factor now. If your ads take a minute to load before your page even starts, what do you think your searh rank will be?

    Even then, most ads are so badly designed that they prevent users from viewing the page. Even to the extreme of page hijacking through redirections. In those cases no one will even see your page. If ads were well thought out and unobtrusive there wouldn’t be adblock software. Ads that are disruptive, like on the cable channel AMC, make me think twice before I watch their movie. Or use a DVR so the last 10 minutes of the movie doesn’t take 40 minutes of my life.

    Author Response: Why do I, the person giving you content essentially for free, have to “earn your trust”. This is like saying the grocery store has to earn your trust before you start paying them for the food you take from the store.

    Regarding the load time issue, why would a webmaster want to rank high in Google if doing so requires they have to not make money off their content? The load time is trivial and, from experience and vast amounts of research, I can assure you that load times are an insignificant factor in search rankings at this time.

    I believe you are wrong that most ads are so badly designed that they prevent users from viewing the page. The overwhelming majority of ads are either textual (Google Adsense) or simple image banners. However, here is the important thing: if the ads are disruptive, then leave the site. Search Google for another site that has less intrusive information and go there instead. If a grocery store is charging $30 for a box of cereal, you don’t just take the cereal. You leave the store and buy it somewhere else. If it is the only store that sells the cereal, you may go talk to the manager about how ridiculous the price is. But at no point is taking the cereal without paying an acceptable, ethical response.

  22. another admin
    Aug 25, 2011

    Your comparison is just wrong. I am paying for the “cereals”, as in “I pay my broadband access”, but no cereal maker can force me to read everything written on the package! I am able to carefully select what part of the package (if any) I want to read. Evenso, I can carefully select which part of the “website” I want my browser to load. And, as a more fitting comparison, regarding to your other post: If I REQUEST your HTML page, I want my browser to fetch your HTML page, but NOT ads that come from a totally different server (or even totally different domain). There is so totally NO way for you to compare paying for a package of cereals to “paying” for showing your website. If you want to be paid for getting your website to show, make it a paid access site.

    Author Response: Sorry, but you clearly misunderstood the point. In my example, cereal is the product, the grocery store is the business, you are the consumer, and $30 is the price. The grocery store can’t force you to pay $30 dollars for the cereal. You have every right to just not buy that cereal, and shop elsewhere. In the online world, content is the product, the webmaster is the business, you are the consumer, and Ads are the price. The webmaster can’t force you to look at his or her ads. You have ever right to just not read their content and go elsewhere to get it. What is unethical, however, is to take the cereal without paying just like it is unethical to take the content while blocking the ads. What is so hard about this concept folks? If you don’t like the ads, don’t view the content. It is that simple. Hit the back button, a skill that most 4 year olds have accomplished well before they reach kindergarten, and move along. You are not entitled to the webmasters’ content.
  23. Joe
    Nov 16, 2011

    I block adverts because they detract from content. I don’t block google textual adverts. If I had to endure any other adverts to look at your content, i probably wouldn’t bother; your content isn’t worth it.

  24. Fetid
    Nov 23, 2011

    “You are not entitled to the webmasters’ content.”

    And you are not entitled to advertisement revenue.

    You keep comparing the Internet to a store, but that just demonstrates that you do not really understand the Internet very well. They are very dissimilar.

    My web browser sends a single request to your web server for a single resource. Your web server happily responds with the resource. It does not tell you that there is a price. You did not configure it that way. It just sends the request there.

    Author Response: Actually, it did tell you there is a price. You have the code before it is displayed. The very technology used to block ads is doing just what you are saying is untrue. It is finding the “price” on the page and choosing to hide it. The unfortunate truth is that ad-blocking is driving webmasters to find ways to hide and obscure that “price” more and more. Interestingly enough, I proposed a meta tag standard for ad-blocking a long time ago which was picked up by adblockplus.

    Perhaps most importantly, though, your ad blocker does not inform you that the webmaster is soliciting remuneration for their content either. You have no clear way to determine whether or not to show the ads because they are prematurely blocked, without consideration to how tastefully they may have been presented in the page.

    Now, here I am, and I have downloaded the resource, and here you are, NOW you are telling me that there is a price. If you want to make more comparisons to the more corporal world, it would be like this….

    Suppose most people in the world has a secretary. Now suppose every one of these secretaries have been trained in a new language designed just for exchanging documents, pictures, and other things by mail. This language has several words for all sorts of things, but the really important one for our purposes is “GET”. All secretaries know the word “GET”, but only some are trained to respond to it.

    You hired one of those specially trained secretaries. You have instructed her to respond every time she receives the word “GET” in a letter along with the name of a document in her filing cabinet. Only one document can be sent back for every word “GET” received.

    So, having given her some instructions, you retire to your office where you begin pounding out more papers. After each is done, you put it in your secretary’s filing cabinet, so she knows that it is available for request.

    The secretaries that most people use just send the word “GET” and don’t reply to “GET”. These are the sort of secretaries that send the word “GET” to your secretary. As only one document is ever sent back, and some documents need more documents or photographs to be complete, people that write the documents can leave addresses in their papers to tell the receiving secretaries where they can send “GET” to receive those missing pieces.

    These secretaries, being good secretaries, never leave anything out of a document if they can help it. Every resource mentioned in the copy they receive is requested so their bosses can be presented with the complete work. You, and many like you, realize that this is a good way to make some money, as you can put addresses to advertisers in these papers, and the good secretaries will diligently request each one and paste it into the document. The advertiser pays you, and you’re happy.

    Well, one day, people start telling their secretaries to not bother mailing the word “GET” to the advertising agencies. They comply. Of course, this upsets you terribly, since you can not get paid by the advertisers if you can’t make naive secretaries request their advertisements by mail, so, in one of these papers, you bather and moan and whine about morals and ethics and how the Internet works without really understanding any of them.

    My secretary still ignores your advertisement addresses.

  25. Zaiken
    Dec 3, 2011

    If it is downloaded to my computer, I will ALWAYS have a say. Ads are often security risks regardless of where they originate. Sure you can block a person from your site; but if your blocking so many I would think you are loosing a fair amount of business. I also block ads because many give me a headache trying to find what I want, as will happen when they are placed in such a way their wording makes the reader think its what they are looking for. It happens more than you might think.

  26. Fetid
    Dec 7, 2011

    “Actually, it did tell you there is a price. You have the code before it is displayed.”

    No, the web server did not tell me. It did not say, “YOU MUST AGREE TO VIEW ALL ADS CONTAINED IN WHATEVER CONTENT YOU RECEIVE.”

    No.

    It just sent me the content, and there are some URLs scattered in there. By the time my equipment parses the ad markup, the content is already in my possession.

    You are giving things away for free, but then complaining that people do not do what you expect with what you give them. Any conditions or stipulations about how one may use the content must be presented before you actually yield it. Good luck getting the HTTP spec changed to suit your BLAAAG.

  27. SILENT
    Sep 24, 2012

    Dude if you don´t want people to run through your site for free, make your page a paid site.
    If you wanna capitalize on everyone regardless their preferences I believe thats beyond a realistic point of view not to say a dirty pig.
    By the way, I first started using No Script and AdBlock because I COULD NOT TRUST the content on that AD world.
    Webmasters provided ad sponsorships the space but never took the time to examine the code being run behind the AD and this generated all kinds of vulnerabilities to the browser.
    I personally WILL ALWAYS USE ABP and No Script, not doing so would be like having sex without protection.

    Author Response: Like Adsense. You can totally get viruses from letting through adsense. I got a better idea. How about you write a simple extension that checks if anything on the page is going to be blocked by NoScript or Adblock and then DONT GO TO THAT PAGE. Why do you feel like you are entitled to consume someone else’s content without the ads?
  28. CyBrChRsT
    Apr 6, 2013

    I’ve published how to effectively block ads using both DNS or your local hosts file.

    http://blog.unxvm.net/freebsd/ad-blocking-filtering-via-bind-dns-named-conf-or-local-hosts-file

Submit a Comment

Your email address will not be published. Required fields are marked *