Code Monkey

19 Feb

Detecting Ad Block Plus

Ad blocking plus is great for browsing sites, but what if you want to actually be supported by ads and ad blocker is stealing all your page views.

Well the solutions is very easy.

on your site have javascript file lets call it script.js

in in that page just have one line:

AdsShowing = true;

then in you page that displays the ads have this code:

<script type=“text/javascript” language=“javascript”>
var AdsShowing = false;
</script>
<script  type=“text/javascript” src=“http://www.yoursite.com/script.js?link=http://pagead2.googlesyndication.com/pagead/show_ads.js”></script>
<script type=“text/javascript”>
 if (!AdsShowing)
{
alert(“BLOCKED”);
}
</script>

Ad blocker will think that your javascript file is an ad link and that code won’t be executed.  Hence AdsShowing will  be false and cause the alert to trigger.

So you can either block all code from executing or the page, give them a mean spirited alert, or a place a box saying hey jerko look at my ads.  You can handle it anyway you want.

Leave a Reply

© 2009 Code Monkey | Entries (RSS) and Comments (RSS)

Global Positioning System Gazettewordpress logo