Devnote

Web Development Blog Company, Services India

MySQL Error 121 Duplicate key on write - Practical Repair Strategy
MySQL Error 121 Duplicate key on write – Practical Repair Strategy
February 13, 2026
PHP cURL error 60: SSL certificate problem - Windows & Linux Fix
PHP cURL error 60: SSL certificate problem – Windows & Linux Fix
February 11, 2026
Fix localhost refused to connect After Installing XAMPP / WAMP
Fix “localhost refused to connect” After Installing XAMPP / WAMP
February 9, 2026
Composer Error Memory exhausted When Installing Packages - Real Fix
Composer Error: Memory exhausted When Installing Packages – Real Fix
February 6, 2026
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci - Safe Migration Guide
MySQL 8 Error Unknown collation: utf8mb4_0900_ai_ci – Safe Migration Guide
February 4, 2026
Devnote

Type and hit Enter to search

  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
Devnote
  • Home
  • Laravel
    • Auth
    • Migration
    • DATATABLE
    • Yajra
  • wordpress
    • plugin
    • WPBakery
    • woocommerce
  • PHP
    • MYSQL
    • Ajax
  • Blog
  • Informational
    • About us
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
  • Contact US
How to Detect AdBlock using HTML CSS & JavaScript

How to Detect AdBlock using HTML CSS & JavaScript

Image
Devnote team
February 8, 2023
3
1.6K Views
0 Comments

Today we will learn How to Detect AdBlock using HTML CSS & JavaScript. In this tutorial, you’ll learn how to Detect AdBlock using JavaScript. In the earlier blog, I shared Detect Internet Connection using HTML CSS & JavaScript.

AdBlocker is a content filtering, that blocks check online ads from interrupting your browsing experience. This code helps the user prevent unintended flashing banners, pop-ups, and online advertisements from being displayed.

Detect AdBlock using JavaScript can see in the preview image, there is a popup box with text and a button to dismiss the popup. If the user has enabled AdBlocker, then this popup will be open; if not, then this popup will close.

Detect AdBlock using JavaScript

To create this program [Detect AdBlock using JavaScript]. First, we need to create two files: one index.html and another style.css file. After creating these files, just paste the below codes into your file.

Example

HTML File

Create an HTML file with the name index.html and paste the below codes into your HTML file.

#index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Detect AdBlock using JavaScript</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>

<body>
    <div id="adsDetect"></div>
    <div class="ads-wrapper">
        <div class="ads-content">
            <div class="exclamation-icon">
                <span class="icon"><i class="fas fa-exclamation"></i></span>
            </div>
            <h2>AdBlock Detected!</h2>

            <p>Welcome to <b>Devnote</b></p>
            <p>It looks like you're using an ad-blocker!</p>
            <p><b>Devnote</b> is an advertising supported site and we noticed you have ad-blocking enabled.</p>
            <p><b>Please turn off your Ad-Blocker</b></p>

            <div class="ads-btn">
                <div class="background-layer"></div>
                <button class="okay">Okay, I'll Whitelist</button>
            </div>
        </div>
    </div>

    <script>
        const adsDetect = document.querySelector("#adsDetect");
        const adswrapper = document.querySelector(".ads-wrapper");
        const button = adswrapper.querySelector(".okay");

        let adClasses = ["ad", "ads", "adsbox", "doubleclick", "ad-placement", "ad-placeholder", "adbadge", "BannerAd"];
        for (let item of adClasses) {
            adsDetect.classList.add(item);
        }

        let getProperty = window.getComputedStyle(adsDetect).getPropertyValue("display");

        if (!adswrapper.classList.contains("show")) {
            console.log(getProperty);
            getProperty == "none" ? adswrapper.classList.add("show") : adswrapper.classList.remove("show");
        }

        button.addEventListener("click", () => {
            adswrapper.classList.remove("show");
        });
    </script>

</body>
</html>

CSS File

Create a CSS file with the name style.css and paste the below codes into your CSS file.

#style.css

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@700&family=Poppins:wght@400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    font-family: "Poppins", sans-serif;
    box-sizing: border-box;
}

body {
    width: 100%;
    height: 100vh;
    background: linear-gradient(#159957, #155799 100%);
}

.ads-wrapper {
    position: absolute;
    max-width: 480px;
    top: 50%;
    left: 50%;
    width: 100%;
    background: #fff;
    padding: 40px 30px;
    opacity: 0;
    pointer-events: none;
    border-radius: 16px;
    box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.06);
    transform: translate(-50%, -50%) scale(1.2);
    transition: opacity 0.2s 0s ease-in-out, transform 0.2s 0s ease-in-out;
}

.ads-wrapper.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.ads-wrapper .ads-content,
.ads-content .exclamation-icon,
.exclamation-icon .icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ads-wrapper .ads-content {
    flex-direction: column;
}

.ads-content .exclamation-icon {
    height: 115px;
    width: 115px;
    border-radius: 50%;
    background: linear-gradient(#159957, #155799 100%);
}

.exclamation-icon .icon {
    height: 100px;
    width: 100px;
    background: #fff;
    border-radius: inherit;
}

.exclamation-icon .icon i {
    background: linear-gradient(#159957, #155799 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 50px;
}

.ads-content h2 {
    font-size: 32px;
    margin-top: 35px;
}

.ads-content p {
    font-size: 17px;
    margin-top: 20px;
    text-align: center;
}

.ads-btn {
    height: 57px;
    width: 223px;
    margin-top: 30px;
    border-radius: 50px;
    position: relative;
    overflow: hidden;
}

.ads-btn .background-layer {
    height: 100%;
    width: 300%;
    position: absolute;
    left: -100%;
    background: linear-gradient(#159957, #155799 100%);
    transition: all 0.4s ease;
}

.ads-btn:hover .background-layer {
    left: 0;
}

.ads-content .okay {
    position: relative;
    z-index: 1;
    height: 100%;
    width: 100%;
    background: none;
    font-size: 18px;
    border: none;
    outline: none;
    color: #fff;
    cursor: pointer;
}

::selection {
    color: #fff;
    background: #159957;
}

Now you’ve successfully created How to Detect AdBlock using HTML CSS & JavaScript. If you’ve faced any errors then please
download the source code files from the given download button.

Download Code

Categories:

CSSHTMLjavascript

Other Articles

How to Add Custom Dropdown in DataTable
Previous

How to Add Custom Dropdown in DataTable

How to create Livewire Datatables Using Laravel
Next

How to create Livewire Datatables Using Laravel

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Fix iOS Safari input type="file" Not Opening Camera - Real Solution

Fix iOS Safari input type=”file” Not Opening Camera – Real Solution

February 16, 2026
The Rise of ES2025: What's New in JavaScript?

The Rise of ES2025: What’s New in JavaScript?

January 24, 2025
HTML Marquee tag

How to use HTML Marquee tag

January 23, 2025
CSS List Property With Example

CSS List Property With Example

December 10, 2024
Devnote

Devnote provides a collection of tutorials about PHP, Laravel, WordPress, Django, MySQL, Bootstrap, Jquery, Ajax, APIs, CRUD operations, etc.

Devnote © , All Rights Reserved.

Page Links

  • Home
  • About us
  • Blog
  • Contact US
  • Site map

Category

  • PHP
  • Laravel
  • wordpress
  • HTML
  • jQuery

Follow Us

Facebook Instagram Twitter Youtube Linkedin Pinterest
Morbi, Gujarat, India - 363641
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT
Advertisement
Advertisement