Advertisement
A_GUES

HTML AdBlocker

May 30th, 2023
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>AdBlocker Detection</title>
  5.   <script>
  6.     document.addEventListener('DOMContentLoaded', function() {
  7.       var adBlockEnabled = false;
  8.      
  9.       // Create a dummy ad element
  10.       var testAd = document.createElement('div');
  11.       testAd.innerHTML = '&nbsp;';
  12.       testAd.className = 'adBanner';
  13.      
  14.       // Append the dummy ad element to the document
  15.       document.body.appendChild(testAd);
  16.      
  17.       // Check if the dummy ad element is blocked or hidden
  18.       if (testAd.offsetHeight === 0 || testAd.style.display === 'none') {
  19.         adBlockEnabled = true;
  20.       }
  21.      
  22.       // Remove the dummy ad element
  23.       document.body.removeChild(testAd);
  24.      
  25.       // Display a message based on the result
  26.       if (adBlockEnabled) {
  27.         document.getElementById('adBlockMessage').style.display = 'block';
  28.       } else {
  29.         document.getElementById('adBlockMessage').style.display = 'none';
  30.       }
  31.     });
  32.   </script>
  33.   <style>
  34.     #adBlockMessage {
  35.       display: none;
  36.       background-color: #f2dede;
  37.       color: #a94442;
  38.       padding: 10px;
  39.       margin: 10px;
  40.     }
  41.   </style>
  42. </head>
  43. <body>
  44.   <h1>AdBlocker Detection Example</h1>
  45.  
  46.   <div id="adBlockMessage">
  47.     <p>It appears that you have an AdBlocker enabled. Please disable it to view the content.</p>
  48.   </div>
  49.  
  50.   <!-- Rest of your content goes here -->
  51. </body>
  52. </html>
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement