0

I am eager to put this answer given to another question into practice:

https://stackoverflow.com/a/20505898/2174961

However, I am not very familiar with JavaScript and I don't know how to complete the code that goes in the body. How do I include the location of the image to be shown when the condition is true?

<script>
    if( window.canRunAds === undefined ){
      // adblocker detected, show fallback
    showFallbackImage();
    }
</script>
Community
  • 1
  • 1
Eva G.
  • 135
  • 1
  • 2
  • 9
  • 1
    You watch/read a few JS tutorials and stop asking for every part of everything you want. It will be faster. – Lee Fogg Aug 23 '14 at 20:49
  • Modify what `showFallbackImage()` does, or write your own. – Shomz Aug 23 '14 at 20:52
  • Lee Allan: I did earnestly try googling for more than 5 minutes, including looking in the tutorial at w3schools.com where I taught myself HTML/CSS back in the day, but I failed to find the answer. Shomz: How would one modify it? – Eva G. Aug 23 '14 at 21:09
  • Find what it does in the original script... But the solution that James gave you is just as good. – Shomz Aug 23 '14 at 21:20
  • If you look at the link in the OP, you'll see that there is no such original script to refer to. Apparently the poster assumed people would know what to do, but I for one didn't. I am trying to implement James' solution but still have questions for him as well. It's not easy being a newbie, but I appreciate the help! – Eva G. Aug 23 '14 at 21:31

1 Answers1

2

I'm not precisely sure what you are trying to do, but from the question you linked, you want to post an image asking people not to use adblock, right?

If so, perhaps the SIMPLEST way to approach this problem might be to place an image tag in your html, with a specific id, and change the display style of the image to hide or unhide it.

<img src="http://path/to/your/image" id="fallbackImage" class="hide" />

Using the following css classes, you can alter the display mode of that image

#fallbackImage.hide {
    display: none;
}

#fallbackImage.show {
    display: initial;
}

In your javascript, you can display this image by changing its css class:

function showFallbackImage() {
    document.getElementById("fallbackImage").className = "show";
}
James M. Lay
  • 2,270
  • 25
  • 33
  • OOPS posted too soon! Let me write my comment out... Thank you for replying. I am so much a newbie that I'm not sure where to place the second piece of code you wrote. Does it go within the script I posted in the OP and if so where? "From the question you linked, you want to post an image asking people not to use adblock, right?" No, actually not, because that would be against Google AdSense policy as they don't want sites calling attention to ads (i.e. soliciting sympathy clicks). (If the OP of the original question is using AdSense, he's playing with fire in terms of risking a ban.) – Eva G. Aug 23 '14 at 21:01
  • I am so much a newbie that I'm not sure where to place the THIRD piece of code you wrote (before it was the second piece, but that was before your answer was edited). Does it go within the script I posted in the OP and if so where? – Eva G. Aug 23 '14 at 21:15
  • 1
    Yes, you can put it in that very same script before or after what was already there. Don't forget to put the css styles in a – James M. Lay Aug 23 '14 at 21:22
  • 1
    Roger! Thank you for the help and also for the advice. I do understand that entry-level questions can be annoying (and I did in fact sincerely try to google first). Appreciate the help! – Eva G. Aug 23 '14 at 21:32