anti-contentBlocker.js :
If you place Google AdSense code on your web page, this script will work well.
If you place Google AdSense code on your web page, there is a very simple way to ditect Blockers with simple JavaScript code.
An AdSense code will append IFRAME elements to its INS element ( that has 'adsbygoogle' class attribute ) when it has been executed successfully.
So you can detect user's AdBlocker enabled ( or not ) to count the number of IFRAME elements in <ins class="adsbygoogle"> element, when the web page has been fully loaded.
That is :
Here is an example code of Google AdSense.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- adsense sample --> <ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-xxxxxxxxxxxx" data-ad-slot="xxxxxxxxxxxx"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
And here is an example of JavaScript code to count IFRAME elements in the elements that have an class name of "adsbygoogle".
function detectBlocker( ){ var ad = document.getElementsByClassName( 'adsbygoogle' ); if( ad.length == 0 )return; /* No AdSense code in this web page. */ if( ad[0].getElementsByTagName('IFRAME').length == 0 ){ /* No IFRAME found. AdSense code has not been executed. */ /* Do Something for AdBlocked user. */ doSomething(); } }
And attach this function to window.onload event.
window.addEventListener('load', detectBlocker, false);
That's all.
But you should write a function doSomething() which does action against AdBlocked users. See below, an sample script is available.
This is the sample script of anti-AdBlocking.
Installation guide is here . Anti-contentBlocker is enabled in the landing page. Turn on your browser's AdBlock Extension and visit Installation guide page, you can see anti-contentBlocker.js in action.
This script displays the following message when AdBlocker was detected.
If the browser language is set to Japanese (ja or ja-JP), the message will be displayed in Japanese. Except Japanese, in English.
For more detail, see here.