Skip to content Skip to sidebar Skip to footer

Run An Ajax Request On A Url Blocked For Detecting Adblocker (ghostery)

I need some simple code for detecting a blocked url. SethWhite has said: You could also try to run an ajax request on a URL blocked by an adblocker. If it succeeds, there's no adbl

Solution 1:

Edit: For microAjax, look up its documentation. I'd imagine in the response you can find the response code. If the code is 200 it's a success, and you can run window.open(). Otherwise, the request is likely being blocked.

  var request = new XMLHttpRequest();
  request.onreadystatechange = function() {
    if(request.readyState === 4 && request.status === 200 ) {
      console.log('No blocker');
    }
    elseif(request.readyState === 4 && request.status === 0){
      console.log('Blocker exists');
    }
  };
  request.open("GET","pathTo/ads.html");
  request.send();

This uses a local URL; I initially thought using external URLs was a good idea, but if they're made invalid by their owners you'll get false positives.

I tested this using Adblock Plus and it works. If this is a URL blocked by Ghostery it should work as well; otherwise, you can try different URLs to see what's blocked.

You could also do this with jQuery's $.ajax function, but I gravitate towards vanilla JavaScript.

Post a Comment for "Run An Ajax Request On A Url Blocked For Detecting Adblocker (ghostery)"