Created
May 23, 2022 13:58
-
-
Save AnjanaMadu/16e426fc01ec9b18da5b3530d3539777 to your computer and use it in GitHub Desktop.
A script or code can detect whether the client uses or enable the ad blocker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
<script> | |
$.ajax({ | |
url: 'https://static.doubleclick.net/instream/ad_status.js', | |
success: function( data ) { | |
console.log("Ads loaded"); | |
}, | |
error: function( data ) { | |
console.log("You're using an ad blocker."); | |
document.body.innerHTML = '<center><br><h1>Turn off your Ads Blocker and refresh the page!</h1></center>'; | |
} | |
}); | |
</script> |
don't use jQuery for every small things 🥺😐
// create a XHR object var xhr = new XMLHttpRequest(); // open the XHR object in asynchronous mode xhr.open("GET", "https://static.doubleclick.net/instream/ad_status.js", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { // OK! we have a successful response. console.log("Ads loaded"); // do something else with the response } else { console.log("You're using an ad blocker."); } }; // make the request xhr.send();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
don't use jQuery for every small things 🥺😐