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:
/
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.
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/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.
Share Improve this question edited Feb 7, 2012 at 14:23 Charles 51.5k13 gold badges106 silver badges144 bronze badges asked Feb 7, 2012 at 10:52 HannesHannes 8,2475 gold badges34 silver badges51 bronze badges2 Answers
Reset to default 2You 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").
Give the iframe an id, then you can check for the existence of the iframe using javascript.
Here's an example:
<script type="text/javascript">
if(document.getElementById("ad") == null) {
alert("The ad has been removed!");
}
else
{
alert("It's alright, it's still here.");
}
</script>
EDIT: Just fixed an error.
What this does is gives Javascript a means of accessing your ad element. The Javascript code that es after (if(document.getElementById("ad") == null)
) just checks if the element exists - if it doesn't, it means the adblocker has removed it.
Some adblockers (like the earlier versions of AdBlock for Chrome) just hide the element, instead of removing it - I'll leave that as an exercise for you to do, because I've only ever checked CSS on DOM elements through JQuery.
EDIT 2:
Using this answer here, you could simply check if the HTML in the iframe loaded properly, and respond based on that.