Papermashup

Subscribe


Tweets


"Website brief: “I need this website up and running no later than ‘yesterday’, as I should already be selling in ord… https://t.co/P3MLikV1V8"

@ashleyford 14 hours ago

"Several things wrong with this. Firstly the ad wasn’t even being shown anymore. There were just 17 complaints. And… https://t.co/4AsYewNFBP"

@ashleyford 16 hours ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Papermashup

Detect an AdBlocker with JavaScript

AdBlockers are web browser plugins, extension or addon that block adverts such as Google Adsense

AshleyAshley

Adblockers are big business on the internet today, but how can you detect if a user is using an adblocker? The answer is pretty simple and only requires a few lines of code. First we need to set a variable to ‘true’, then we load a javascript file called adframe.js within this JavaScript file we set the variable to ‘false’. The adblocker will detect and block any javascript file containing the word Ad, Advert etc, so if the file is blocked our original variable we set will read ‘true’.

The Code


<script type="text/javascript">
var adblock = true;
</script>
<script type="text/javascript" src="adframe.js"></script>
<script type="text/javascript">
if(adblock) {
alert('You have an adblocker enabled');
}else{
alert('No adblocker detected');
}
</script>

Demo Download

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 0
There are currently no comments.