Detect any AdBlocker with Javascript code.

// This is react example.

import { useEffect } from ‘react’;

const hello = () => {
useEffect(() => {
const timeoutId = setTimeout(() => {
const adBoxEl = document.querySelector(“.ad-box”);
const hasAdBloc…


This content originally appeared on DEV Community and was authored by sagarjaid

// This is react example.

import { useEffect } from 'react';

const hello = () => {
    useEffect(() => {
        const timeoutId = setTimeout(() => {
            const adBoxEl = document.querySelector(".ad-box");
            const hasAdBlock = window.getComputedStyle(adBoxEl)?.display === "none";
            console.log(hasAdBlock, "hasAdBlock");
            // ... save to DB
        }, 1000);
        return () => clearTimeout(timeoutId);
    }, []);

    return (
        <div className="ad-box" style={{ position: "fixed", top: 0, left: 0 }} aria-hidden="true">
            &nbsp;
        </div>
    );
}

export default hello


This content originally appeared on DEV Community and was authored by sagarjaid


Print Share Comment Cite Upload Translate Updates
APA

sagarjaid | Sciencx (2023-05-07T21:31:48+00:00) Detect any AdBlocker with Javascript code.. Retrieved from https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/

MLA
" » Detect any AdBlocker with Javascript code.." sagarjaid | Sciencx - Sunday May 7, 2023, https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/
HARVARD
sagarjaid | Sciencx Sunday May 7, 2023 » Detect any AdBlocker with Javascript code.., viewed ,<https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/>
VANCOUVER
sagarjaid | Sciencx - » Detect any AdBlocker with Javascript code.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/
CHICAGO
" » Detect any AdBlocker with Javascript code.." sagarjaid | Sciencx - Accessed . https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/
IEEE
" » Detect any AdBlocker with Javascript code.." sagarjaid | Sciencx [Online]. Available: https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/. [Accessed: ]
rf:citation
» Detect any AdBlocker with Javascript code. | sagarjaid | Sciencx | https://www.scien.cx/2023/05/07/detect-any-adblocker-with-javascript-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.