Warning: Cannot modify header information - headers already sent by (output started at /home/lalienoits/www/index.php:48) in /home/lalienoits/www/inc/cookie.php on line 6
a cadenza discontinua
Come se fossi

Detect AdBlock (Anti AdBlock)

Hard times, AdBlock is a useful tool for surfers but penalizing for the owners of websites, blogs or other. Personally I do not gain anything but I pay the costs of the blog and allows me to continue writing. In addition to sponsored articles it is the only "entry". I think this year there will be a new layout of the sisto using boostrap, which allows me to make the site responsive and delete the mobile version. Today I explain very quickly the most common techniques to find out if the visit has installed AdBlock and then to show a message or whatever you want. Personally I prefer to warn that to prevent navigation, even if I fully understand that there are people who live there.

Let's analyze the first case: Adsense

The detection of Adsense is one of the most common cases and is easily implemented, at the end of the page load we will check if the ads have been successfully uploaded otherwise we will show an altert or whatever you want.

  window.onload = function() {
    setTimeout(function() {
      if ( typeof(window.google_jobrunner) === "undefined" ) {
	alert("Per sostenere questo sito disabilita AdBlock.");
        console.log("ad blocker installato");
      } else {
        console.log("nessun ad blocker installato.");
    }, 10000);  

Obviously where the jquery alert is present it will be possible to insert any warning even in the limiting form, that is, obscuring the site or other.

The second case is based on loading a js file named ads.js. The adblockers try to prevent the loading of this js and then through a small check we can verify the loading

<script>var isAdsLoaded=false;</script><script src="js/ads.js"></script><script>
if (!isAdsLoaded) { 
  console.log("The visitor is blocking ads");

The ads.js file will only be composed of the line isAdsLoaded = true; trivially it is based on a variable that only varies if the js file is loaded. ads.js can be included in any path.


di GuiZ


We'll never share your email with anyone else.