Some think adblock is good and ads are bad.. some other think adblock is bad and ads are good cos they support the free internet...
today i do not want to discuss if adblock is good or bad, i will instead show you how you can detect ad-blocking visitors on your website. once you have detected the visitors who are blocking your ads you can either give them an annoying message at each page load or simply block them from accessing your content.
sources:
http://thepcspy.com/read/how_to_block_adblock/
http://www.adblock.org/2004/07/adblock_detection_demo/
Method 1: Detecting the size of ad divs
live example:
http://blockadblock.nodesforum.com/?_nodesforum_permalink=2#_nodesforum_anchor_2
simply put your banner ad(s) into a div.
example:
code:
<div id="my_ad_div">
<!-- google ad code... -->
</div>
|
and then (not too fast to not check before ad is loaded) detect the height of this ad div with javascript.
example:
code:
<script type="text/javascript">
function jabbahud()
{
if(document.getElementById("my_ad_div").offsetHeight==0)
{alert("you are blocking my beautiful ads!");}
}
window.onload=jabbahud;
</script>
|
it seems that adblock, in order to do a good job not only blocks your ads but removes the space they occupy on the page, so if a div only contained that ad, when the ad is there the div will have a certain height, but once adblock removed the ads the div will then have a height of 0px;
we can then use javascript to check the height of the ad div after the page is loaded and if it has a height of 0px then the visitor is probably blocking your ads.
the good side of this method is that it will work for most adblocking software with mostly any defenition. the bad side of this method is that it is only applicable to banner ads.
Method 2: Detecting if banner.gif? is blocked
live example:
http://blockadblock.nodesforum.com/?_nodesforum_permalink=3#_nodesforum_anchor_3
i guess it depends on each special rules set that you run on your adblock, but at least the rules set that was suggested to me as beeing the *most popular does it, and adblock themselves are suggesting to use this method to detect their ad-blocking software (
http://www.adblock.org/2004/07/adblock_detection_demo/ ) even though for some reason their suggested code did not appear to work for me i was able to fix something that works for me based on that idea.
first what you do is place a picture called banner.gif? on your page
example:
code:
<img src="banner.gif?" width=1 height=1 id="job"> |
(it does not matter if the picture really exists on your server or not)
then just detect the "offsetHeight" (javascript) of the picture to see if adblock has removed it.
example:
code:
<script type="text/javascript">
function jabbahud()
{
if(document.getElementById("job").offsetHeight==0)
{alert("i detect adblock..");}
}
window.onload=jabbahud;
</script>
|
the good side of that method is that it will work even if your ads are something else than banners.
note that theres also easy ways to make it so that your content will not come up for those who have javascript disabled, to avoid that people bypass your protections just by turning off javascript.
example:
code:
<div id="nojs">please enable javascript to view the content.</div>
<div id="content" style="display:none;">
content... blah blah...
</div>
<script type="text/javascript">
document.getElementById("nojs").style.display="none";
document.getElementById("content").style.display="block";
</script>
|
this will initially make the div that says to turn on javascript visible and the div that contains your content hidden. then javascript will hide the div that asks you to enable javascript and make the content div visible.
------------------------
tested on Firefox on Windows with and without adblock, Opera on Windows without adblock, Internet Explorer 8 on Windows wihtout adblock and Chrome on Windows without adblock.
so thats it, i will let you know if i ever find any other method. your comments are welcome, registration is not required to reply!