Anti-adblock that replaces div [duplicate]

this question already has an answer here : How to change the contents of a DIV if you are using adblock (1 response) Closed 2 years ago .

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

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

Already tried the Plugins:

JGC AdBlocker Detector - this one does not accept style (shows the style as if it were plain text)

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

Author: Randrade, 2018-04-25

2 answers

You can use the BlockAdBlock (or FuckAdBlock)

As I answered in: https://pt.stackoverflow.com/a/87992/3635

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

<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>

Assuming the element is something like:

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

Alternative

If you are using googleanalitycs you could use 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>
 3
Author: Guilherme Nascimento, 2018-04-25 17:09:50

There are several ways to detect ad blocks, but none is 100% guaranteed, I tested a script taken from an answer from @ Guilherme Nascimento: https://pt.stackoverflow.com/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>

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

Hope I helped!

 2
Author: Dobrychtop, 2018-04-25 19:46:41