Anti-adblock which replaces div

Asked

Viewed 731 times

0

I need a wordpress plugin or script in which present a message to the user who has Adblock.

However, I want that message to appear in place of a div.

I’ve tried the plugins:

JGC Adblocker Detector - This does not accept style (shows the style as plain text)

Ad Blocker Notify Lite - This works on the local server, but does not work on the online server.

2 answers

3

You can use the Blockadblock (or Fuckadblock)

as I replied in: /a/87992/3635

If you have jQuery (usually wordpress uses) can do so:

<script src="blockAdBlock.js"></script>
<script>
(function() {
    function adBlockDetected() {
        $(function () {
            $('#div_especifica').text("adblock detectado");
        });
    }

    function adBlockNotDetected() {
        console.log("Sem adblock");
    }

    if(typeof blockAdBlock=== 'undefined') {
        alert("blockAdBlock não foi carregado");
    } else {
        blockAdBlock.onDetected(adBlockDetected);
        blockAdBlock.onNotDetected(adBlockNotDetected);
        blockAdBlock.on(true, adBlockDetected);
        blockAdBlock.on(false, adBlockNotDetected);
        blockAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
    }

    blockAdBlock.setOption('checkOnLoad', false);

    blockAdBlock.setOption({
        debug: true,
        checkOnLoad: false,
        resetOnEnd: false
    });
})();
</script>

Supposing the element is something like:

 <div id="div_especifica"></div>

Alternative

If you’re using googleanalitycs you could use it like this:

<script>
function possivelAdblockDetectado () {
    $(function () {
        $('#div_especifica').text("adblock detectado");
    });
}
</script>

<script onerror="possivelAdblockDetectado()" async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
    style="display:inline-block;width:300px;height:250px"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="6440411535"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
  • I do not know if I did wrong, but I tried to put to replace a class, but even with Adblock on appear, "blockAdBlock was not loaded".

  • @Marcio.Sx you added the <script src="blockAdBlock.js"></script> in the <head>? You know you have to put blockAdblock.js inside your website right?

  • The blockAdBlock.js file should be called right?! XD

  • I called blockAdBlock.js, but now nothing appeared! Should appear "detected Adblock" in place of div né?

  • @Marcio.Sx looks in the browser console if there is no error.

  • No error, look what appears:[Blockadblock][setoption] The option "debug" he was Assigned to "true" blockAdBlock.js:57 [Blockadblock][setoption] The option "checkOnLoad" he was Assigned to "false" blockAdBlock.js:57 [Blockadblock][setoption] The option "resetOnEnd" he was Assigned to "false"

  • @Marcio.Sx edited the answer, try now

  • I changed the way you told me to and still nothing!

  • @Marcio.Sx puts a alert within the possivelAdblockDetectado, thus function possivelAdblockDetectado () { alert('testando'); }, if an Alert appears on your site it is because the problem is not Blockadblock.

  • Did not give Alert, I did so: Function adBlockDetected() { Function possibleAdblockDetected () { Alert('testing'); } }

  • 1

    This code will never run yet and is not the same as what I posted @Marcio.Sx, please do exactly as I did in the reply.

  • You have helped me more expensive, thank you! I do not understand much of js, so I will call my friend he will understand your answer. I am eternally grateful! :-)

  • @Marcio.Sx Go like this, change to this only: function adBlockDetected() { alert('testando'); }

Show 8 more comments

2

There are several ways to detect ad blocks, but none is 100% guaranteed, I tested a script taken from a reply by @Guilherme Nascimento: /a/87992/3635

<script>
    function possivelAdblockDetectado () {       
        document.getElementById("id-div").innerHTML = "Conteúdo html que você quer mostrar no lugar";
}
</script>

<script onerror="possivelAdblockDetectado()" async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>

That one script tries to load Google’s ADS, if not possible, due to ad blocking (or any other reason), it will call a function possivelAdblockDetectado (), and in it you can exchange the contents of div you want.

I hope I’ve helped!

  • 4

    Our answer looks exactly like my code https://answall.com/a/293984/3635 - assuming you copied some of it would be really cool if you did? After all, to go around copying other people’s code without quoting the source is to belittle your colleagues' efforts, don’t you agree? Even the name of the function possivelAdblockDetectado is equal :/

  • I do not remember if it was your answer, probably yes, but not this one of the comment, the 2015, I use this script for some time now, for this answer I took from my msm code, qq way I added the credits, sorry qq thing.

  • Copy the wrong link, it was to be the 2015, thank you for crediting!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.