Adblock is blocking iframe redirects - how to detect?

Hannes picture Hannes · Feb 7, 2012 · Viewed 7.7k times · Source

I have page that performs a lot of redirects inside an iframe where the targets are mostly affiliate network pages (that perform redirects to shops and so forth), the markup looks something like:

http://jsfiddle.net/HPDNC/2/

As you can see, if you have an ad blockerk enabled the iframe doesn't load. I need to somehow detect that so I can ether make a direct redirect or at least inform the user of the situation.

The normal way would be to simply check the ad or what not to detect if an ad blocker is active. Unfortunately, there are no actual ads on this page to check.

Answer

Linus Kleen picture Linus Kleen · Feb 7, 2012

You can detect whether or not a site of yours is visited with Ad-Blockers. In the <head> tag, - or really anywhere - put this:

<script type="text/javascript">
window.ADS_BLOCKED = true;
</script>
<script type="text/javascript" src="/advertise/detect.js"></script>
<script type="text/javascript">
if (window.ADS_BLOCKED)
   alert('You blocked me...');
</script>

The included Javascript detect.js would set window.ADS_BLOCKED to false. Ad-Blockers would prevent this file from loading because of its filename ("advertise").