Skip to content

Instantly share code, notes, and snippets.

@elvisciotti
Created November 7, 2018 16:47
Show Gist options
  • Save elvisciotti/fc3b7acd0356b6c60d675da0c5436700 to your computer and use it in GitHub Desktop.
Save elvisciotti/fc3b7acd0356b6c60d675da0c5436700 to your computer and use it in GitHub Desktop.
ad blocker detect.html
#https://stackoverflow.com/questions/4869154/how-to-detect-adblock-on-my-website
# ads.js
var canRunAds = true;
# site template after <body>
<script>
if( window.canRunAds === undefined ){
// adblocker detected, show fallback
document.body.innerHTML += '<div class="fullpageoverlay"><p>You must disable adblocker to use this website</p></div>';
}
</script>
# optional (footer, with jquery enabled)
$.ajax({
url: "/ads.js", // this is just an empty js file
dataType: "script"
}).fail(function () {
document.body.innerHTML += '<div class="fullpageoverlay"><p>You must disable adblocker to use this website</p></div>';
});
# style.css
# https://stackoverflow.com/questions/1719452/how-to-make-a-div-always-full-screen
.fullpageoverlay {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
background: rgba(51,51,51,0.7);
z-index: 9999999;
}
.fullpageoverlay p {
font-size: 2em;
background-color: #FFF;
padding: 50px;
margin: 50px;
width: 500px;
color: #FF0000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment