How to show different content from website server when AdBlock is detected?
Problem :
The ads you placed on your website are not showing up because they were blocked by browsers based plugin like AdBlock or AdBlock Plus. You want to find a way to detect Ad Blocker, block your content and show a message.... asking the user to disable or pause AdBlock.
How to do that with Javascript/Jquery js file and server side programming languages such as PHP, Ruby, Golang, Perl and web frameworks?
Solution :
For this tutorial, we use PHP as an example for this method and you can easily replace the PHP code with the programming language that you preferred.
- First, create a
<div>
where you will print out the content data. - Next, evaluate the Javascript variable
adblock
and if theadblock
value is TRUE then replace the<div id="content">
's innerHTML to whatever message you want to tell your visitors.
<div id="content">
<?php
print $content;
?>
</div>
<script type="text/javascript">
var adblock = true;
</script>
<script type="text/javascript" src="adframe.js"></script>
<script type="text/javascript">
if(adblock) {
document.getElementById("content").innerHTML='<p>Hello, please disable Adblock and reload this page to see the content.</p>';
}
</script>
Content of adframe.js:
adblock = false;
To test, please activate AdBlock and view this page. You should see the content is blocked until you turn off the AdBlock.
When better spears are around, better shields will come out .... and the cycle goes on and on....
UPDATE : One of the many ways to defeat this content blocking method is to view your page content in text only that are cached by Google or other search engines. Ya know, some visitors will go all the way just to get the content without pausing Adblocker. You can instruct the search engines not to cache your page content with one simple instruction in the robots.txt file
User-agent: * Noarchive: /
There are couple of more ways to defeat this content blocking method...but it is time for me to shut up now on this topic
Reference :
http://stackoverflow.com/questions/18180598/ad-blocker-detection-aka-adblock-plus
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+13.5k Golang : Check if an integer is negative or positive
+4.5k Unix/Linux : How to pipe/save output of a command to file?
+13.6k Golang : convert(cast) string to float value
+7.1k Golang : Scanf function weird error in Windows
+4.5k Golang : How to pass data between controllers with JSON Web Token
+28.2k Get file path of temporary file in Go
+5.3k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+16.1k CodeIgniter/PHP : Create directory if does not exist example
+18.7k Golang : Check whether a network interface is up on your machine
+7.9k Golang : Append and add item in slice
+10.9k Golang : How to determine a prime number?
+15k Golang : Find location by IP address and display with Google Map