Ad Blocker detection AKA Adblock Plus

前端 未结 15 1352
北海茫月
北海茫月 2020-12-02 06:14

After searching Google and Stackoverflow for a few hours I could not find a solution. What I\'m trying to do is detect Adblock plus and display a simple message for now.

15条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 06:32

    For me none of the tricks worked, may something I was doing wrong. but this is a very specific way to implement for google ads.

    window.onload = function() {
       if (document.getElementsByClassName('google-auto-placed').length == 0){
                    // Adblock Detected
       }        
    }
    

    If you have other ad system like amazon, look for their generic class name / ids by inspecting page.

    If you are planing to put this code in seperate .js file make sure file name does not have "Ad" word in it. just name it magic.js

    If Google ever decides to change div name, this method would fail. but that seems unlikely.

提交回复
热议问题