Search code examples
jqueryruby-on-railsrubyadblock

Ruby on Rails - different jQuery results in development and production for adblock message


In my application I added some jQuery codes to show a message when user has adblock on. In my development ENV I can see the message, but with same code in production ENV it doesn't work/do the same thing.

Here is my code

var canRunAds = true;
  function hallo(){
    $("#showmsg").html("<p>You are using adblock</p>");
  }
  if( window.canRunAds === undefined ){
    hallo();
  }

I even created a file called showads.js and included it to my head with var canRunAds = true; but in production it changes to var canRunAds != 0; for reasons.

How can I get it to work or is it something I do wrong?


Solution

  • Here is how I got it to work. Changed showads.js to ads.js and added code blow to footer.

      $(document).ready(function(){
        if( window.canRunAds === undefined ){
            $("#showmsg").html("<p>You are using adblock</p>");
        }
      });
    

    It looked like adblock didn't block showads.js but ads.js