Skip to content

Instantly share code, notes, and snippets.

@kandran
Last active August 29, 2015 14:20
Show Gist options
  • Save kandran/e71f87c8102e4b426906 to your computer and use it in GitHub Desktop.
Save kandran/e71f87c8102e4b426906 to your computer and use it in GitHub Desktop.
AdBlock detection

#AdBlock Detection

One way to detect AdBlock is to create a file named advert.js, set a var inside and in another script detect if this specific variable has been created. If not the advert.js file has not been load probably by adBlock.

window.ab = false;
if (!('ab' in window)) {
window.ab = true;
}
if (window.ab == true) {
console.log('AdBlock is enabled');
} else {
console.log('AdBlock is disabled');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment