0

Hey any one know how to prevent users to use ad blocker on my site.I just want to request them not to use it on my site..

Hassan Munir
  • 15
  • 1
  • 4
  • 4
    The traditional approach is to place an image behind (`z-index`) ad spots that say "Please don't block our ads". – Dai Oct 10 '14 at 18:45

1 Answers1

3

Make a Javascript file called advertisement.js with this code:

var noadblock = true;

Include it on your page somewhere:

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

The idea is that adblock will block the file called advertisement.js and your var will never be created. So you can use this to take action based on whether the var exists or not:

window.onload = funtion(){
    if (noadblock){
        // no adblock
    }else{
        // adblock detected, do stuff here
    }
}

Updated cus somone in the comments had a better idea.

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • 2
    Why not just set a variable in advertisement.js? For example, `adsNotBlocked = true;`. Then just check `if (!adsNotBlocked)` – David Sherret Oct 10 '14 at 18:56
  • good point +1 @DavidSherret – I wrestled a bear once. Oct 10 '14 at 19:05
  • Heh I like this option. – ceejayoz Oct 10 '14 at 19:10
  • @Adelphia please create a java script for me.m new to website and i know enough about these thing m learning though.please creat a file and send to me at supershaheens@gmail.com .i shall be very thankful to you. – Hassan Munir Oct 13 '14 at 06:08
  • @HassanMunir Firstly, no. SO isn't a place to get free coding done. My Instructions were pretty straight forward. Open notepad, paste in the single line of code I posted and save it as "advertisement.js". Secondly, now that your question has been answered please mark the check mark to select it. – I wrestled a bear once. Oct 13 '14 at 13:26
  • @Adelphia here is my second question i hope you can help me thanks.http://stackoverflow.com/questions/26377527/how-to-add-categoryposts-in-wordpress-single-post – Hassan Munir Oct 15 '14 at 08:09
  • Thank you @HassanMunir, unfortunately I don't use wordpress but it looks like you've got some good advice on that question. Best of luck. – I wrestled a bear once. Oct 15 '14 at 14:31