11

I wish to detect adblocking software on my website and ask users to disable adblock by redirecting. The only way I found was using Javascript.

  1. Is there any other way of detection ?

  2. If not, how do I detect if Javascript is disabled and redirect them to a certain page ?

5
  • 14
    @Ivo that is horse-shit. I'm all for freedom of choice, but you can't ask small video startups not to use video ads. I guess you can, but then we simply ask you to F off and go use BitTorrent. I'd rather you consume illegal pirated content somewhere else than pay for your CDN streaming costs, pay my licensor his fee and then get nothing in return.
    – Nuby
    Apr 12, 2011 at 17:25
  • 5
    Ivo does have the very good point that you can not force the user to use your service. It is better to make them to want to use it.
    – Johan
    Oct 15, 2011 at 0:33
  • 7
    @Johan What you miss is I don't want them to use my free service if they don't want to view ads. Why should I? I'm not running a charity, I'm running a business. If you want to block ads, but a subscription. If you want it free, then stop wasting my bandwidth
    – John
    Dec 13, 2011 at 2:34
  • 1
    Sometimes "free service" is worth what you pay for it. You can always block freeloaders. AdBlock's stated intent is to help the user "to regain control of the internet" -- which tells me that maybe some people DO think that advertising is out of control. The latest AdBlock whitelists more ads that are less abusive. StackOverflow is information-rich, clear, easy to navigate, very useful, with loyal users. If you think that your site is annoying or abusive, maybe it needs a review. SOf users might be willing - If not, there are other sites specifically for site review.
    – Marc
    Dec 19, 2011 at 20:19
  • i just want to ad, that AdBlock blocks other stuff too. Like Facebook Connect (sometimes at least). That's why I want to detect AdBlock. I have no ads at all on my website Apr 11, 2014 at 11:09

4 Answers 4

34

To detect if the user is blocking ads, all you have to do is find a function in the ad javascript and try testing for it. It doesn't matter what method they're using to block the ad. Here's what it looks like for Google Adsense ads:

if(typeof(window.google_render_ad)=="undefined") 
{ 
    //They're blocking ads, do something else.
}

This method is outlined here: http://www.metamorphosite.com/detect-web-popup-blocker-software-adblock-spam

To redirect all users with javascript disabled, simply put this code in the head of your HTML:

<noscript>
    <meta http-equiv="refresh" content="5;url=http://newsite.com/">
</noscript>
2
  • 11
    ? ads keeps the web running Mar 6, 2013 at 8:02
  • and if google decide to change "google_render_ad" you're screwed... is there no other consistent flag?
    – Filth
    Dec 7, 2015 at 15:21
5

You cannot actually "detect" if javascript is disabled. Since javascript is a client-side feature, the server cannot detect it, and "detecting"things client-side is done with javascript. You see the catch 22.

What is available is the <noscript> tag, which is only rendered by the browser if javascript is turned off. This is the standard mechanism for displaying a message to a user if javascript is disabled. Using noscript and clever CSS you can make it imperative that users either enable javascript or follow a redirect link you present to use your site.

There is no way to automatically redirect only users that have javascript disabled. You can redirect users selectively by using javascript, or you can redirect people based on server-side criteria (HTTP headers, etc.). But you can't catch that middle group.

As for detecting adblocking, this is going to vary by browser and adblocking method. There isn't a consistent flag for it, but you can do things like checking for the availability of your ad server via javascript, or checking if your ad content is loaded on the page.

1
  • You could use JavaScript to render the content the user is interested in. So, no JavaScript, no content. The user would instead get a message that JavaScript is required. Once JavaScript is turned on, you can use it to detect if your ads are being blocked. Sep 5, 2016 at 1:33
2

I quote from this post about the subject:

http://w3guy.com/detecting-adblock/

HTML

<div class="myTestAd">
    <!-- Adsense Ad code goes here -->
</div>

JS:

if ($('.myTestAd').height() == 0) {
    // stuff to do if adBlock is active
} 
1

I couldn't get @Beau's solution to work checking for 'window.google_render_ad' but it did work when checking 'window.google_jobrunner'.

Maybe the Adsense code has changed since the original answer was posted, I found 'google_jobrunner' in the JS downloaded from Adsense but not 'google_render_ad'.

2
  • both work fine for me
    – Andres SK
    Mar 27, 2013 at 16:17
  • I can verify this, window.google_render_ad didn't work but window.google_jobrunner did the trick. Thanks!
    – jesal
    May 9, 2013 at 18:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.