The code presented in this page can be used to detect if the visitor has an Ad-Blocker that blocks Ads in page, and to display a friendly message to visitor when the JavaScript is disabled or Ads are blocked.
The script was tested with Adblock Plus.

Script code

- Just add the following HTML /CSS /JS code in the pages of your website.

border:2px solid #0000be;

<div id='jsad_notify'>
Parts of this site works with JavaScript enabled; and without AdBlock.<br>
Please consider supporting us by disabling your Ad-Blocker on this website.

//if JavaScript enabled, it hides #jsad_notify
var jsad_notify = document.querySelector('#jsad_notify'); ='none';

//adds a child-element in page which usually is blocked by Ad-Blocker
var test_adb = document.createElement('div');
test_adb.innerHTML ='&nbsp;';
test_adb.className ='adsbox';
 //if Ads blocked it shows the message, else it removes the #jsad_notify
 if(test_adb.offsetHeight ===0) ='block';
 else jsad_notify.outerHTML ='';

 document.body.removeChild(test_adb); //removes test_adb elm.
}, 700);

To change the position and design of the message, edit the CSS properties of the #jsad_notify element.

Daily Test with Code Example

Which HTML5 tag can be used to embed an external application (SWF, PDF) in web page?
<mark> <embed> <canvas>
<embed src="flash_game.swf" width="450" height="350" />
Which CSS pseudo-element adds a special style to the first line of a text?
:first-letter :before :first-line
#id:first-line {
  font-weight: bold;
  color: blue;
Click on the window object property which gets or sets the URL of current page.
window.location window.self window.status
var url = window.location;
Indicate the PHP function used to get the contents of a file or page and store it into a string.
fopen() file_put_contents() file_get_contents()
$homepage = file_get_contents("");
echo $homepage;
Show a message if JavaScript disabled or Ad-Blocker

Last accessed pages

  1. sPBM - Simple PHP Backup Manager (1456)
  2. Multiple Select Dropdown List with JavaScript (10105)
  3. Integer and Float value in Select with PDO from string to numeric (6528)
  4. Send POST data with file_get_contents (1230)
  5. Add Tag to Selected Text in textarea with JavaScript (1929)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (306)
  2. Register and show online users and visitors (207)
  3. Read Excel file data in PHP - PhpExcelReader (176)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (171)
  5. JavaScript Course - Free lessons (137)