检测adblock并邀请guest虚拟机禁用的新方法

时间:2014-04-22 19:33:03

标签: javascript css adblock

我是JS的新手,我正在努力了解它。

我已经看到很多关于此的问题,但似乎没有一个独特的答案来解决这个问题,也没有一个明确的代码来实现。

浏览几个NFL网站我发现他们已经实现了一个有趣的代码,我很想知道它是如何工作的,以及是否可以复制它。

他们的detect-blocked-ads.js显示了这一点:

//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();
    }
}

如果启用了广告拦截,那么它们会在页面顶部显示一个CSS彩色块。

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

我很想知道如何调用此函数来显示JS文件中附带的代码或消息。

谢谢

0 个答案:

没有答案