私は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 ファイルに添付されたコードまたはメッセージを表示する方法を知りたいです。
ありがとう