【问题标题】:Disable download button when AdBlock is detected检测到 AdBlock 时禁用下载按钮
【发布时间】:2016-04-10 22:36:28
【问题描述】:

我的网站上有很多视频剪辑可供下载。下面的代码实现了这一点。 现在我知道如何检测用户是否安装了 AdBlock,这些链接帮助了我: 1 help1

2 help2

3 help3

对于大多数这些解决方案,如果检测到 AdBlock 但没有实施更多“更严格”的操作,则会显示“一般”自定义消息,因此当用户单击“下载”时,“下载”输出是否也可能是诸如“您需要启用广告才能显示才能下载视频剪辑”之类的消息,而不是用户可以实际下载文件???

HTML 下载:

<div class="box download-box">
     <a class="button" href="">
          <i class="fa fa-download"></i> Download
     </a>
</div>

HTACCESS:

<FilesMatch "\.(mov|avi|mp4)$" >
   ForceType application/octet-stream
   Header add Content-Disposition "attachment"
</FilesMatch>

【问题讨论】:

  • 不要。只是不要。
  • 如果您使用ads.js 解决方案(来自help2),只需将添加按钮的代码添加到您的ads.js 文件中(而不是将其直接放在您的HTML 中)。如果ads.js 被阻止,则没有下载按钮。当然,这不会阻止一个有足够决心和技术能力的人。

标签: javascript jquery adsense adblock


【解决方案1】:

简答:

是的,你可以。

长答案:

就我而言,我通常会在页面加载时向服务器发送信息,包括是否在客户端启用了广告拦截器,因此我会阻止将媒体发送到浏览器。

如何检测:

我做了一个小脚本,可以检测到你可以在 Github detect-adblocker找到更多信息。

使用它非常简单。您只需要在 head 标签的顶部添加脚本,例如:

<head>
<!--adBlocker detection code - START-->
    <script src="//adblocker.fortiapp.com/ads.js"></script>
    <script>
        (function (i, o, g, r) {
            i[o] = (typeof i[o] == typeof undefined) ? g : r
        })(window, 'adblocker', true, false);
    </script>
    <!--adBlocker detection code - END-->

    // some other scripts if any
</head>

然后稍后在您的主应用中执行:

if(adblocker){
    // send information to the server that ad blocker is active and
    // therefore prevent whatever you want from being sent to the user
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多