PDA

View Full Version : How-to: Detect ad-blockers on your site



Apolva
03-07-2010, 12:48 PM
This is a quick and easy tutorial on how to detect if someone is using an ad blocker on your site (eg. Adblock Plus), and display them a message to nag them not to. Please do not use this tutorial to block access to your site entirely or display annoying alerts for those that do.

Demo:
Without an ad-blocker, an advert is displayed. With an ad-blocker, an alternative message is displayed.
http://www.habbopfm.com/

Step 1:
Make a file named "adverts.js" on the root directory of your site (eg. www.yoursite.com/adverts.js (http://www.yoursite.com/adverts.js)) with the following code:

loa=true;Step 2:
Add the following code just after your <body> tag:

<script>loa=false;</script><script src="/adverts.js"></script>Step 3:
The final step is displaying the message - add the code below where your ads would be (you can change the style and text of the message):

<script>if(!loa)document.write("<div style='text-align:center;color:red;font-size:20px;font-weight:bold;background:#000;padding:10px;'>Our site is funded entirely by our sponsers.<br />Please do not block adverts on this page.</div>");</script>How it works
This method of detection works by beating the ad-blocker at its own game - the blocker won't load anything it believes to be an advert, in this case "adverts.js", which simply sets a variable when it is loaded. If the variable isn't set, the file must have been blocked, and the message is displayed.

Limitations
This method can be circumvented by white-listing the "adverts.js" file. To prevent this, you could use several files with varying names.

Jahova
03-07-2010, 01:08 PM
Sponsors* and also a very nice script! Will help some people and their sites for sure.

FlyingJesus
03-07-2010, 01:19 PM
I don't know like.. anything at all about coding and such but would there not a way through this trick to just display the ads anyway to really piss everyone off :P

Jamesy
03-07-2010, 07:14 PM
I don't know like.. anything at all about coding and such but would there not a way through this trick to just display the ads anyway to really piss everyone off :P

Possibly. But really the idea here is to make people realise that as annoying as they may be, adverts are what provide the income many sites need to run, and maybe to reconsider.

Want to hide these adverts? Register an account for free!