Web developers often encounter the problem of ad blockers, which can interfere with a site’s functionality. One way to solve this issue is by detecting the ad blocker using JavaScript. In this article, we’ll look at a simple method for checking the activity of an ad blocker and alerting users.
How it works: We create two elements:
div element that is often blocked by ad blockers.If one of these elements fails to load or is not visible, it means the ad blocker is active, and we can display an alert to the user.
Code example:
<script>
(function() {
var adElement = document.createElement('div');
adElement.className = 'adsbox reklama';
adElement.style.height = '10px';
adElement.style.position = 'absolute';
adElement.style.top = '-9999px';
document.body.appendChild(adElement);
setTimeout(function() {
var isAdBlockActive = adElement.offsetHeight === 0;
if (isAdBlockActive) {
alert('Блокувальник реклами активний! Будь ласка, вимкніть його');
}
document.body.removeChild(adElement);
}, 300);
})();
</script>
Conclusion: This method effectively detects ad blockers on your site and alerts users about their presence. By doing so, you can improve the user experience and ensure your content functions properly.
Activation and Initialization Hooks in WordPress: Where and When to Create Tables
160
How to Create a Custom Table in WordPress via functions.php: A Complete Guide to MySQL Data Types
109
HTML Select: hidden placeholder, highlight, and dynamic urgency indicator
157
How to Create a Custom Admin Menu in WordPress: A Simple Guide for Beginners
107
Customizing the WordPress Login Page: Logo, Colors, Background Image & Custom CSS
138
How to Display the Visitor’s IP Address on a Website Using PHP? 497
Adding Meta Description and Keywords in WordPress 344
How to Add a Currency Widget to the WordPress Admin Dashboard 186
How to Add a “Department” Field and Restrict Category Visibility in WordPress 165
Minimum Order Amount WooCommerce 163
I’m sorry, but I constantly get the text “Блокувальник реклами активний! Будь ласка, вимкніть його.”, even when adblock is turned off
What am I doing wrong?
Posted on: 19.11.2025
<script> (function() { var adElement = document.createElement('div'); adElement.className = 'reklama'; // название, которое блокируют adElement.style.height = '1px'; adElement.style.width = '1px'; adElement.style.position = 'absolute'; adElement.style.top = '-9999px'; adElement.style.left = '-9999px'; var adImage = new Image(); adImage.src = "/ads/reklama.jpg"; // путь, похожий на рекламу document.body.appendChild(adElement); document.body.appendChild(adImage); setTimeout(function() { var isAdBlockActive = false; if (adElement.offsetHeight === 0) { isAdBlockActive = true; } if (adImage.height === 0) { isAdBlockActive = true; } if (isAdBlockActive) { alert('Блокувальник реклами активний! Будь ласка, вимкніть його.'); } document.body.removeChild(adElement); document.body.removeChild(adImage); }, 1000); })(); </script>I’ve added 100% working code to the article. Please review the changes.