PDA

View Full Version : How to detect AdBlock on your site?



yipman
03-17-2018, 01:02 AM
How to detect adblocking software on your site with little help of javascript. It works for both AdBlock and AdBlock Plus. So let's start.

First you need to create advertisement.js file on your hosting. It is important that it is called that way because adblocking software will triggered by it. Put this code in it:


document.write('<div id="tester">an advertisement</div>');

Now you have to insert this code right under <body> tag:


<script type="text/javascript" src="/advertisement.js"></script>

<script type="text/javascript">
if (document.getElementById("tester") == undefined){
window.location = "http://yourlandingpage/adblock.html";
}
</script>

With this code you will redirect users to your landing page where you can ask them to disable adblocking software in order to approach your page. This second part of this code can be edited any way you want and I will show it to you later in this post.

And as final part you have to insert this code into your CSS file or into <style></style> in head of your HTML:



#tester {
display:none;
}

So this is it. You have AdBlock detector on your site :D

And now if you don't want to redirect users to landing page you can just warn them with pop up or with one paragraph. To do that you have to remove this part from original code:



window.location = "http://yourlandingpage/adblock.html";

And replace it with this code for pop up:



window.alert("Your pop up warning!");

And for paragraph you have to replace it with this code:


document.write('<p>Your paragraph waring!</p>');

Of course, if you use paragraph as a warning, you have to place second part of original code where you want it to be.

You can also edit it any way you like it.