Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Adblock detection in website using javascript

async function detectAdBlock() {
  let adBlockEnabled = false
  const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'
  try {
    await fetch(new Request(googleAdUrl)).catch(_ => adBlockEnabled = true)
  } catch (e) {
    adBlockEnabled = true
  } finally {
    console.log(`AdBlock Enabled: ${adBlockEnabled}`)
  }
}
detectAdBlock()
 Run code snippetHide results
Comment

PREVIOUS NEXT
Code Example
Javascript :: match date regex 
Javascript :: jquery delay 
Javascript :: js regx for number validation 
Javascript :: email validator javascript 
Javascript :: datatable set placeholder 
Javascript :: deploy react app netlify 
Javascript :: angular lifecycle hooks 
Javascript :: remove duplicate objects from array javascript 
Javascript :: javascript get all keys of object 
Javascript :: create file node javascript 
Javascript :: nuxt scroll to top 
Javascript :: javascript round decimal 
Javascript :: js get domain 
Javascript :: show div js 
Javascript :: how to check if object exists in javascript 
Javascript :: day name date js 
Javascript :: js timestamp 
Javascript :: javascript persistent storage 
Javascript :: fs move file 
Javascript :: json watch command 
Javascript :: angular download blob pdf 
Javascript :: joi enum validation 
Javascript :: javascript redirect to relative url 
Javascript :: display none javascript 
Javascript :: how to use await to console 
Javascript :: npm json server 
Javascript :: javascript clear classlist 
Javascript :: remove space from string javascript 
Javascript :: add color to console 
Javascript :: get column from 2D array javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =