Best Practice to Detect Ad blocker is Enabled with JavaScript – WordPress Tutorial

By | July 16, 2019

If you plan to design a wordpress adblocker plugin, the first step is to detect ad blocker is enabled or not. In this tutorial, we will introduce a common used method. You can learn and do by our tutorial.

disable adblocker to show images

Detect Ad blocker is Enabled with JavaScript

        if ( typeof(window.google_jobrunner) === "undefined" ) {
		displayMask(d);
	}

In javascript code above, if a browser enable an ad blocker, typeof(window.google_jobrunner) will be undefined.

This method can detect google adsense ads is blocked or not by ad blocker, if you want to detect other ads, you can check this example code.

Create a javascript file named ads.js

Add code in this file.

var canRunAds = true;

Detect adblocker is enabled or not.

<script type="text/javascript" src="js/ads.js"></script>
<script>
  if( window.canRunAds === undefined ){
	// adblocker detected, show fallback
	do();
  }
</script>

This code can work on almost ad blockers, then you can add your process function.

Leave a Reply