Skip to content

Instantly share code, notes, and snippets.

@isaumya
Created January 8, 2017 07:11
Show Gist options
  • Save isaumya/4d73c3ce57c5ed5e64bc1528df50dba8 to your computer and use it in GitHub Desktop.
Save isaumya/4d73c3ce57c5ed5e64bc1528df50dba8 to your computer and use it in GitHub Desktop.
Show some message to the users when they are using AdBlocker on your website
/** IMPORTANT NOTE:
* Make sure you put this JS in the footer of your site
* and not to include in a file and then load it in the defer or async way
* Otherwose the script may not work properly.
*
* Though this script was written keeping WordPress in mind, but it can be used
* on any CMS or in any sites. Enjoy :)
*
* Custom script written for www.iSaumya.com/blog/ by Saumya Majumder in 2016
**/
jQuery(function ($) {
if( ( $( '.adgoogle' ).length > 0 ) ) ) {
var content = '<div class="some-class">Put your HTML text here, which you want to show to the users when they are using AdBlocker</div>';
var flag = 0;
if ( typeof( window.google_jobrunner ) === "undefined" ) {
flag = 1;
}
if( $( '.adgoogle' ).length > 0 && flag === 1 ) {
$( '.adgoogle' ).html( content );
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment