📜  使用 javascript 代码示例在网站中检测广告拦截

📅  最后修改于: 2022-03-11 15:01:27.655000             🧑  作者: Mango

代码示例1
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