4

我的页面在 iframe 内执行大量重定向,其中目标主要是附属网络页面(执行重定向到商店等),标记看起来像:

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

如您所见,如果您启用了广告拦截器,则 iframe 不会加载。我需要以某种方式检测到这一点,以便我可以进行直接重定向或至少将情况告知用户。

正常的方法是简单地检查广告或不检测广告拦截器是否处于活动状态。不幸的是,此页面上没有实际的广告可供查看

4

2 回答 2

2

您可以使用广告拦截器检测您的网站是否被访问过。在<head>标签中 - 或者真的在任何地方 - 把这个:

<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>

包含的 Javascriptdetect.js将设置window.ADS_BLOCKEDfalse. 广告拦截器会阻止加载此文件,因为它的文件名(“广告”)。

于 2012-02-07T11:02:35.163 回答
0

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 comes 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.

于 2012-02-07T11:09:14.587 回答