DharmeshPHP
DharmeshPHP

Reputation: 41

Possible ways of detecting Adblock? I've tried so many things

So recently I've signed up to adsense and put in on my URL shortening project. The ad currently is displayed on the header of the site. (Above the navbar). And when users have Adblock enabled, it pretty much ruins the header part of the site.

Now I did my research, I found a topic here already, but that didn't help me at all.

If anyone has any good ways of detecting adblock, would appreciate it!

Upvotes: 0

Views: 811

Answers (2)

radiofrequency
radiofrequency

Reputation: 873

adblock works by blocking resources from this list: https://easylist-downloads.adblockplus.org/easylist.txt

pick a file that matches the list for ex:

ad1.js

create that file and make it accessible to your site and add this code to it:

window.adblock = false;

now in your app js put:

window.adblock = true;
$.getScript("/js/ad1.js");

now when you go to show an add just check window.adblock to see if adblock is enabled.

if (window.adblock)
  console.error("adblock is enabled")
else
  console.log("adblock is not enabled show ads")

Upvotes: 1

Chaoley
Chaoley

Reputation: 1292

function handle_adsense_blocker() {

 if (typeof(window.google_jobrunner) == 'undefined') {

  // doesn't seem to work for opera
  if ( navigator.userAgent.match(/opera/i) ) {

   return;

 }

 // replace Adsense ads with something else

 }

}

// add this to your window load event
window.setTimeout('handle_adsense_blocker()', 3000);

Upvotes: 0

Related Questions