Detecting AdBlocking software?

前端 未结 10 1410
梦谈多话
梦谈多话 2020-12-13 01:10

I was recently visiting a site and noticed that the page had a section that said it noticed that I was using AdBlocking software and could I kindly turn it off to help suppo

相关标签:
10条回答
  • 2020-12-13 01:31

    I found this part in the code which seems to look like how they did it:

    /*MOOTOOLS*/
    window.addEvent('domready', function(){
    
    $$('.cat-item').each(function(el) { 
        var fx = new Fx.Morph(el,{ duration:300, link:'cancel' }); 
            el.addEvents({ 
            'mouseenter': function() { fx.start({ 'padding-left': 25 }); }, 
            'mouseleave': function() { fx.start({ 'padding-left': 15 }); } 
            }); 
        });
    
        if ($$(".google-sense468")[0] && $$(".google-sense468")[0].clientHeight == 0 && $('block-warning')) $('block-warning').setStyle('display','block');
    
    });
    /*MOOTOOLS END*/
    
    0 讨论(0)
  • 2020-12-13 01:35

    You can add javascript-code to your page, that is only executed if there's no adblocker, e.g. use "ad" as variable-name, use "ad.js" as file-name. This code sends an ajax-event to the server, saying "this user doesn't use an adlocker". So if you don't receive that event, you know, that this user is blocking ads or even javascript altogether.

    0 讨论(0)
  • 2020-12-13 01:36

    All off the methods mentioned here rely on the ad blockers to strip out code. This doesn't work for some adblockers(like NetBarrier on Mac). You also have to keep updating your code when the adblockers catch on.

    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

    0 讨论(0)
  • 2020-12-13 01:37

    I guess there are several ways of doing it, but probably the easiest one would be to have some kind of background image, or text, that will be replaced when the ad is loaded. Thus, if the ad gets loaded, you see the ad. If the ad doesn't load, you see the text.

    This example would be client side, done by either JavaScript or just plain CSS might even suffice.

    There might be some server-side gimmicks that could do this too, but they would be unnecessarily elaborate and clunky. One method that springs to mind would include some kind of API with the advertiser that could be asked "did the user from IP such.and.such load any images?" and in that way get the answer. But I doubt there's such services - it would be much easier to do on the client side.

    0 讨论(0)
  • 2020-12-13 01:41

    What you can do to detect the adblocker on the server-side is somithing like:

    <?php
    
      header('Content-Type: application/javascript');
    
      //Save it to session
      session_start();
      $_SESSION['noAdblocker']=true;
    
     ?>
    
     noAdblocker=true;
    

    Save this file as ads.php

    Now the index.php:

    <?php
      session_start();
      $_SESSION['noAdblocker']=false;
    ?>
    <!DOCTYPE HTML><html><head>
        <!-- Now place the "ad-script" -->
        <script src="ads.php"></script>
    </head><body></body></html>
    
    0 讨论(0)
  • 2020-12-13 01:44

    I don't think there is an easy way to do this. What you can do is to create "trap". Make a php script listen to a very obvious url like yourdomain.com/ad.png. You can probably achieve this by url rewriting. If this page is loaded you can note this in a session variable and send back a 1x1 blank png.

    On the next request you can see whether ad.png has been loaded. If it hasn't you can guess that the client is using some form of AdBlock software. Make sure you set the appropriate http headers to prevent clients from caching "ad.png".

    This is the only server side approach I can think of at the moment and it has some flaws.

    • The png file can be cached regardless of the http headers
    • This will not work for the first http request
    • Some extra server load as browsers will keep hitting ad.png for each request
    • That the image gets loaded from the server is no guarantee for it actually being displayed
    • Probably more side effects that I haven't thought of

    Please make a comment on this post if you decide to try it out.

    Regarding a client side solution. This shouldn't be to difficult. You can create a tiny Javascript to run on page load complete. This script can check that the page contains the dom-nodes holding the ads. If you this when the page is loaded completely (not only the dom) you can check the width and height of your ad images. The most obvious drawback with this solution is that clients can disable javascripts.

    0 讨论(0)
提交回复
热议问题