Javascript Course

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.

<style>
#jsad_notify{
background:#f8f800;
border:2px solid #0000be;
color:#ee0000;
font-size:20px;
font-weight:700;
margin:0;
padding:2px;
position:fixed;
top:40px;left:1%;right:1%;
text-align:center;
max-width:98vw;
}
</style>

<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.
</div>

<script>
//if JavaScript enabled, it hides #jsad_notify
var jsad_notify = document.querySelector('#jsad_notify');
jsad_notify.style.display ='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';
document.body.appendChild(test_adb);
window.setTimeout(function(){
 //if Ads blocked it shows the message, else it removes the #jsad_notify
 if(test_adb.offsetHeight ===0) jsad_notify.style.display ='block';
 else jsad_notify.outerHTML ='';

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

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

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
Show a message if JavaScript disabled or Ad-Blocker

Last accessed pages

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (141749)
  2. Node.js Move and Copy file (28420)
  3. MouseEvent - Events for Mouse (2909)
  4. PHPMailer (2311)
  5. Uploading images to server with Ajax (6095)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (473)
  2. CSS cursor property - Custom Cursors (79)
  3. The Mastery of Love (70)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (62)
  5. CSS3 2D transforms (46)