According to a survey, 10% of people use adblocker for browsing with any ads. It means 10% less revenue by the website. This is sad for the websites that solely rely on ads, some of them use adblocker detecting script and restrict the user to enter the website without disabling the adblocker (But this is a bad idea from an SEO point of view).
Detect adblocker using bait script: In this method, you have to create a div with the class name ad-zone. Make the div 1px height. Now write a script that checks if the offset height of parent div becomes zero, then the user is using an adblocker. The adblocker blocked that div from rendering, so the offset height becomes zero. If the offset height of the div remains unchanged then there is no adblocker present in the browser. The reason is the class name ad-zone, the adblocker used to inspect which element has the class name that looks like an ad.
The easylist.text has a huge list of such class names. Every adblocker has its own set of class names which will be blocked that’s why we should not rely on only one class name. Some common class names are textads, banner-ads, banner_ads, ad-unit, ad-zone, ad-space which are detected by the adblocker for an ad.
We are running our code on jsbin.com and using the extension AdBlock. When the adblocker is running, the following output can be seen.
When the adblocker is turned off for jsbin.com, the following output can be seen.
Example 2: The following code can be used in any webpage under the <script> tag.
Output : You can paste this code in any browser console, or you can use it in a script tag.