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 HTML element can be used to embed a SWF flash content?
<object> <div> <script>
<object type="application/x-shockwave-flash" data="file.swf" width="500" height="250">
 <param name="src" value="file.swf" />
 Your browser not support SWF.
</object>
Which CSS pseudo-class adds a style to an input form field that has keyboard input focus?
:active :focus :hover
input:focus {
  background-color: #88fe88;
}
Click on the instruction which converts a JSON string into a JavaScript object.
JSON.stringify(javascript_object) object.toString() JSON.parse(json_string)
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses"}';
var obj = JSON.parse(jsnstr);
alert(obj.url);
Indicate the PHP function which can be used to create or write a file on server.
fopen() file_put_contents() file_get_contents()
if (file_put_contents("file.txt", "content")) echo "The file was created";
else echo "The file can not be created";
Show a message if JavaScript disabled or Ad-Blocker

Last accessed pages

  1. Using v-model in form input fields (1051)
  2. jQuery UI draggable - Drag elements (11445)
  3. Display data from PHP Array, or MySQL in HTML table (26980)
  4. Redirects (4978)
  5. jsSHA - SHA Hashes and HMAC in JavaScript (3519)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (310)
  2. The Mastery of Love (48)
  3. CSS cursor property - Custom Cursors (36)
  4. Read Excel file data in PHP - PhpExcelReader (35)
  5. PHP-MySQL free course, online tutorials PHP MySQL code (31)