如何在我的网站上检测Adblock? [英] How to detect Adblock on my website?

查看:169
本文介绍了如何在我的网站上检测Adblock?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够检测到用户访问我的网站时是否正在使用adblocking软件。如果他们正在使用它,我想显示一条消息,要求他们关闭它以支持该项目,例如该网站



如果您进入该网站,并且浏览器启用了某种adblock软件,则该网站将不显示实际广告,而是显示一条小横幅告诉用户广告收入用于托管项目,他们应该考虑关闭Adblock。



我想在我的网站上这样做, m在上面使用adsense广告,该怎么办?

解决方案

我的解决方案并不特定于某个广告网络,非常轻巧。我已经在生产中运行了几年。 AdBlock阻止所有包含单词 ads的网址。所以这就是我所做的:



我在我的webroot中添加了一个小js文件,名称为 ads.js



这是该文件中的唯一代码行

  var canRunAds = true; 

然后在我页面的某处:



<上课前= lang-html prettyprint-override> < html>
< head>
< script src = / js / ads.js>< / script>
< / head>
< body>
< script>
if(window.canRunAds === undefined){
//检测到adblocker,显示后备
showFallbackImage();
}
< / script>
< / body>
< / html>

ads.js之类的文件至少受到Chrome上的以下adblocker的阻止:




  • AdBlock

  • Adblock Plus

  • Adblock Pro

  • Ghostery



2019年2月15日更新:



在上面的列表中添加了Ghostery,因为该扩展名现在还阻止了对ads.js的请求。非常便利。



不适用于:



隐私徽章


I would like to be able to detect if the user is using adblocking software when they visit my website. If they are using it, I want to display a message asking them to turn it off in order to support the project, like this website does.

If you enter to that site and your browser has some kind of adblock software enabled, then the site instead of showing the actual ads shows a little banner telling the users that the ad revenue is used for hosting the project and they should consider turning Adblock off.

I want to do that on my website, I'm using adsense ads on it, How can I do that?

解决方案

My solution is not specific to a certain ad network and is very lightweight. I've been running it in production for a few years. AdBlock blocks all URLs containing the word "ads". So this is what I did:

I added a small js file to my webroot with the name ads.js

This is the only line of code in that file

var canRunAds = true;

Then somewhere in my page:

<html>
  <head>
    <script src="/js/ads.js"></script>
  </head>
  <body>
    <script>
      if( window.canRunAds === undefined ){
        // adblocker detected, show fallback
        showFallbackImage();
      }
    </script>
  </body>
</html>

Files like ads.js are blocked by at least these adblockers on Chrome:

  • AdBlock
  • Adblock Plus
  • Adblock Pro
  • Ghostery

Update on 2019-02-15:

Added Ghostery in the list above because the extension now also blocks requests to ads.js. Very handy. Does this mean that Ghostery is actually helping us devs to detect the blocking of ads with their extension?

Does not work with:

Privacy Badger

这篇关于如何在我的网站上检测Adblock?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆