Papermashup

Subscribe


Tweets


"RT @cpray86: Good to see the receptionist's Jpeg of an Excel file is coming along nicely... #TheApprentice https://t.co/uiPGhf64U3"

@ashleyford 1 day ago

"Translation wrong for this paper it should be: Bitte nicht den Horror-Clown (Please not the Horror-clown) https://t.co/RYOD6aND6s via @bandt"

@ashleyford 3 weeks 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.