How to detect AdBlocker using JavaScript ?

0
2051

Ad blocking or ad filtering is a software capability for removing or altering online advertising in a web browser or an application. An ad blocker is a program that will remove different kinds of advertising from a Web user’s experience online.

 

In this article, we are going to detect if an AdBlocker is enabled while an user is surfing your webpage.

These simple 2 steps will allow us to detect whether AdBlocker is enabled/disabled in the web browser :

  1. Create a JavaScript file named adframe.js and include it in the webpage
    Declare a variable adblock in the adframe.js file and save it as :

    var adblock = false;
  2. The basic idea is : if adframe.js file is not loaded by the browser, it means AdBlocker is enabled
    By default we will set adblock = true;

    <script type="text/javascript">
        var adblock = true;
    </script>
    <script src="js/adframe.js"></script>
    <script type="text/javascript">
        if(adblock){
            alert("Please disable AdBlocker for better experience");
        }
    </script>

Instead of alert message, we can provide proper message in a popup or whatever looks appealing. We can request users to disable AdBlocker for better experience of our site.

Follow this video for implementation of the above technique :

ALSO READ  Why Adsense Rejected Your Website: Reasons and Solutions

Comments are closed.