Minimal Adblock/Adblock Plus Detector With jQuery

Minimal Adblock/Adblock Plus Detector With jQuery
File Size: 3.25 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

An ultra-light jQuery Adblock Detector that helps developers to detect if there are extensions for blocking ads (e.g. Adblock, Adblock Plus) currently active in the browser.

How to use it:

1. Download and insert the JavaScript file jquery.adblock-detector.js after jQuery.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" 
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" 
        crossorigin="anonymous">
</script>
<script src="jquery.adblock-detector.js"></script>

2. Detect whether the current browser has Adblock enabled.

$.adblockDetector.detect().done(function(adsEnabled){
  if (!adsEnabled) {
    // do something
  }
});

3. Advanced usage. The plugin uses Sweetalert2 to show a warning popup when there is an Adblock extension is activated in the browser.

<link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.28.11/sweetalert2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.28.11/sweetalert2.min.js"></script>
$.adblockDetector.detect().done(function(adsEnabled){
  if (!adsEnabled) {
     swal({
      title: 'Adblock Detected',
      text: "You won't be able to access this page",
      type: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Disable Adblock'
      }).then((result) => {
      if (result.value) {
        swal(
        'Thank You!',
        'Refresh The Page',
        'success'
        )
      }
      })
  }
});

This awesome jQuery plugin is developed by xxnoobmanxx. For more Advanced Usages, please check the demo page or visit the official website.