Frage

Hi everyone (and Merry Christmas too),

I've just been working on a website which is currently not live yet and I'm trying to account for users that have Adblock Plus installed (i.e. fixing the margins and padding so the layout of the site doesn't break when ABP gets rid of the divs holding the ads).

Currently my jQuery is:

function detectAdBlock() {
    if($('.adsbygoogle').css('display') == 'none') {
        $('.adblock').css('display', 'block');
        $('.adfail').css('display', 'block');
    } else {
        $('.adblock').css('display', 'none');
        $('.adfail').css('display', 'none');
    }
}

$(detectAdBlock);

This works fine for the AdBlock extension for Chrome, but does not do anything with AdBlock Plus.

I have also tried using:

if($('.adsbygoogle').height() == 0) { // Whatever }

but this hasn't worked at all.

I know that having ads is controversial, but I'm just looking for an answer, not an argument about why I shouldn't have ads - and furthermore I'm trying to fix the layout for the people who don't see the ads.

Any help is appreciated!

Thanks.

War es hilfreich?

Lösung

Found the problem, had to use:

$('.adsbygoogle').is(':hidden'))

for ABP. So in the if statement:

function detectAdBlock() {
    if($('.adsbygoogle').css('display') == 'none' || $('.adsbygoogle').is(':hidden')) {
        $('.adblock').css('display', 'block');
        $('.adfail').css('display', 'block');
    } else {
        $('.adblock').css('display', 'none');
        $('.adfail').css('display', 'none');
    }
}

$(detectAdBlock);

Andere Tipps

I'm trying to account for users that have Adblock Plus installed (i.e. fixing the margins and padding so the layout of the site doesn't break when ABP gets rid of the divs holding the ads).

Instead of trying to detect whether or not users have Adblock Plus installed, detect the negative effects that you want to work around. If Adblock Plus removes an advert from the DOM, then look to see if the advert is in the DOM or not.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top