Skip to content

Instantly share code, notes, and snippets.

@howtogeek
Last active January 22, 2020 23:45
Show Gist options
  • Select an option

  • Save howtogeek/6b3ed7d917900229b37e to your computer and use it in GitHub Desktop.

Select an option

Save howtogeek/6b3ed7d917900229b37e to your computer and use it in GitHub Desktop.
Change font to Comic Sans if reader is using Adblock (and display a message at the top)
<script type="text/javascript">
// this is all a hack and requires jQuery
var iframe = document.createElement("iframe");
iframe.height = "1px";
iframe.width = "1px";
iframe.id = "ads-text-iframe";
iframe.src = "/adframe.js";
document.body.appendChild(iframe);
setTimeout(function(){
var iframe = document.getElementById("ads-text-iframe");
if(iframe.style.display == "none" || iframe.style.display == "hidden" || iframe.style.visibility == "hidden" || iframe.offsetHeight == 0) {
$( "body" ).prepend( '<div style="display:block;padding:4px;background:gold">Since we detected you are blocking the ads that pay our bills, we are changing the font to Comic Sans.</div>' );
$('*').css("font-family","Comic Sans MS");
iframe.remove();
}else{
iframe.remove();
}
}, 1000);
</script>
@howtogeek
Copy link
Author

This requires jQuery to work. And you should probably stick it in the footer.

@MaffooBristol
Copy link

Strange combination of vanilla JS and jQuery; why not just make those two jQuery functions use plain JS instead and remove the dependency?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment