Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 5 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 1 week 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.