最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS - Detect uBlock Origin - Stack Overflow

programmeradmin0浏览0评论

I see a lot of posts on how to detect AdBlock/AdBlockPlus but none on uBlock Origin.

Is there a way to detect this Adblocker?

I tried getting a script that was blocked (CoinHive) and trying to check if CoinHive (Class) is undefined. This doesnt seem to work as it didnt actually block the script but instead blocked the CoinHive Websocket Connection.

I see a lot of posts on how to detect AdBlock/AdBlockPlus but none on uBlock Origin.

Is there a way to detect this Adblocker?

I tried getting a script that was blocked (CoinHive) and trying to check if CoinHive (Class) is undefined. This doesnt seem to work as it didnt actually block the script but instead blocked the CoinHive Websocket Connection.

Share Improve this question asked Oct 8, 2017 at 20:52 user8549339user8549339
Add a ment  | 

3 Answers 3

Reset to default 7

I would just check to see if your ads are loaded. easiest way to do that is have a container element with no set width, then just check that it is greater than or equal to a size smaller than your ads...

function uBlockActive(expected_width){
  if ( $('.ad_container').width < expected_width) ) {
    return false
  }
  return true;
}

Edit:

I also found this:

$.ajax('showads.js')
 .fail(function(d){
debugger //do some stuff here
});

the uBlock filters list currently includes a filter that is not found in other ad blockers.

HTML elements of the class name adholder2 are cosmetically hidden with the default settings. I'm using this solution to suggest my visitors to use uBlock origin in case they are using something else.

Most ad blockers I checked have their own lists with their own unique rules.

It works for me.

function uBlockActive(){
  if ( window.adsbygoogle.push.length > 0) {
    return false
  }
  return true;
}
发布评论

评论列表(0)

  1. 暂无评论