0

I'm really new to JS, and I'm trying to learn about it.

I've seen many questions about this, but there seems not to be a unique answer to solve this issue, nor a definitive code to implement.

Browsing though several NFL sites I see they have implemented an interesting code and I'd love to know how it works and if it is possible to replicate it.

Their detect-blocked-ads.js shows this:

//detect if there is an adblock cookie set (has this test been performed before?)
//if not perform the test and save the cookie

$nflcs.detectBlockedAds = function() {
    if($nflcs.cookie('adblocker') == null) {
        $nflcs('body').append('<div id="adblock-notice">We noticed that you may have an Ad Blocker turned on. Please be aware that our site is best experienced with Ad Blockers turned off. <a href="javascript:void(0);" class="close">[X]</a> <div style="clear:both;"></div></div>');
        $nflcs('body').append('<div id="adblock-test" class="bannerAd">This is a test banner</div>');

        $nflcs('#adblock-notice a').click(function(e) {
            $(this).parent().fadeOut('fast');
        });

        if((typeof($nflcs('#adblock-test').css('-moz-binding')) != 'undefined' && $nflcs('#adblock-test').css('-moz-binding').indexOf('elemhidehit') !== -1) || ($nflcs('#adblock-test').css('display') == 'none')) {//adblocker in use
            $nflcs('#adblock-notice').fadeIn('fast');//show the adblock notice
            $nflcs.cookie('adblocker',true,{expires: 3});//save that this test has been performed for 3 days max
        }
        else {//adblocker not in use
            $nflcs.cookie('adblocker',false,{expires: 3});

        }
        $nflcs('#adblock-test').remove();
    }
}

Then they display a CSS colored block on top of the page if there is an adblock enabled.

<div style="display: block;" id="adblock-notice">We noticed that you may have an Ad Blocker turned on. Please be aware that our site is best experienced with Ad Blockers turned off. <a onclick='s_objectID="javascript:void(0);_1";return this.s_oc?this.s_oc(e):true' href="javascript:void(0);" class="close">[X]</a> <div style="clear:both;"></div></div>

I'd love to know how to call this function to show the code or message attached in the JS file.

Thanks

myuption
  • 35
  • 4
  • 6
    As an avid ad-block user - I'd go in and block the ad-block notice...just sayin'...Ad-block users tend to get persnickety when smarty-pants websites try to block or work around Ad-block – fnostro Apr 22 '14 at 19:43
  • 3
    Don't waste your and your users time. The blockers gonna block. – lxgreen Apr 22 '14 at 20:43
  • 2
    I just want to point out a message, in this example they can disable it and that's it. What's wrong in showing ads if they are helpful to pay some bills? – myuption Apr 22 '14 at 21:37
  • possible duplicate of [How to detect Adblock on my website?](http://stackoverflow.com/questions/4869154/how-to-detect-adblock-on-my-website) – Wesley Apr 23 '14 at 04:42
  • I want to know how the jquery works in this case, guess I wasn't able to explain myself correctly. – myuption Apr 24 '14 at 19:22

0 Answers0