Answer the question
In order to leave comments, you need to log in
How to check ad blocking?
We need a script that will check if the user has ad blocking enabled.
I want to implement this on my website
Answer the question
In order to leave comments, you need to log in
Eat to download something that is very likely to be blocked. Check if the resource was loaded successfully.
faced with a similar need, tk. API got into "ru AdList", solved in this way:
export default function detectAdBlock(){
return new Promise((resolve) => {
const adElement = document.createElement("div");
adElement.classList.add('adsbygoogle');
adElement.style.cssText = 'height: 1px; width: 1px; background-color: transparent';
document.body.appendChild(adElement);
const adElementStyle = getComputedStyle(adElement, null);
window.setTimeout(()=>{
if(adElementStyle.display === 'none'){
resolve(true)
}else{
resolve(false)
}
document.body.removeChild(adElement);
}, 20)
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question