【问题标题】:My Website content blocked by AdBlock twitter and [duplicate]我的网站内容被 AdBlock twitter 和 [重复]
【发布时间】:2014-10-13 22:05:05
【问题描述】:

我正在更新我的人事网站,在 Chrome 下安装 adBlock 后,我注意到一些功能失常。我发现 adBlock 阻止了我网站上的一些资源,例如 twitter-timeline 脚本和 linkedin.pnp 图像。我禁用 adBlock 一切恢复正常。 是否有一些 Javascript 代码可以知道浏览器何时具有阻止扩展并要求用户禁用它?

谢谢

【问题讨论】:

  • 大多数网站都有通常被广告隐藏的内容,因此当广告被屏蔽时,用户可以看到这些内容。例如:“我们看到您安装了 AdBlock。我们需要从广告中获得收入来保持该网站的运行”在与广告的确切大小和形状相同的 div 中,但在广告所在的容器下方。

标签: javascript adblock


【解决方案1】:

首先,您必须包含一个名为 ads.js 的 JavaScript 文件。由于 AdBlock Plus 的过滤规则,该文件被自动阻止。因此我们可以使用这个文件来做一些我们可以稍后测试的东西,看看用户是否使用了广告拦截器。

<script type="text/javascript" src="advertisement.js"></script>

其中的内容是:

document.write('<div id="tester">an advertisement</div>');

该文件将一个元素写入我们稍后将测试的页面。 CSS 规则使该元素不可见:

#tester {
    display:none;

现在我们在希望显示消息的位置使用另一段 JavaScript。这将测试我们之前创建的“tester”div 的存在。如果它在那里,则意味着 ABP 没有阻止我们的 ads.js 文件,一切都很好。如果不存在,则表示某种软件阻止了 advertisment.js,因此我们可以在页面上写一条特殊消息。

<script type="text/javascript">
if (document.getElementById("tester") != undefined)
{
    document.write('<p class="yes">No <strong>AdBlock Plus</strong> detected! Thanks for truly supporting our site.</p>');
}
else
{
    document.write('<p class="no">We\'ve detected that you\'re using <strong>AdBlock Plus</strong> or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising. To read more about why you should disable ABP, please <a href="#">click here</a>.<!-- end .content --></p>');
}
</script>

Here是答案的来源。

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 2021-08-01
    • 2010-10-03
    • 2023-01-29
    相关资源
    最近更新 更多