admin管理员组文章数量:1406444
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.
本文标签: javascriptAdblock is blocking iframe redirectshow to detectStack Overflow
版权声明:本文标题:javascript - Adblock is blocking iframe redirects - how to detect? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745012872a2637656.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论