How to detect AdBlock on your site?

Many of the visitors make use of Adblock softwares to block ads from websites. Doing this has prons as well as cons. Today I will teach you 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";
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 {
So this is it. You have AdBlock detector on your site.

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.

Link your website with us for free!


About Author

I’m Vinay Vernekar , a young Entrepreneur and a Technology blogger, currently living in Kolhapur, Maharashtra, India. Founder and Main author of Fun With Tricks. I am also running web hosting services at Host With Us and King Of Web Host. if you like this article, pin it with social media, subscribe to our newsletter. Follow me on Google Plus, Facebook, Linkedin and Twitter.

Know more about me!

Mail me your quries at

Get Free Email Updates to your Inbox!

Post a Comment

You are always welcome to leave valuable feedback!