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 ?

Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
Dheeraj
  • 233
  • 1
  • 5
  • 14
  • 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 '11 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 '11 at 00: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 '11 at 02: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 '11 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 – ProblemsOfSumit Apr 11 '14 at 11:09

4 Answers4

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>
Beau
  • 1,771
  • 1
  • 15
  • 20
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.

Gabriel Hurley
  • 39,690
  • 13
  • 62
  • 88
  • 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. – Mark Micallef Sep 05 '16 at 01: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
} 
W3Guy
  • 657
  • 1
  • 7
  • 16
vsync
  • 118,978
  • 58
  • 307
  • 400
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'.

Chaoley
  • 1,282
  • 15
  • 21