Show popup when adblock is active
<p>I use this simple code to detect if adblock is active</p>

<pre><code>&lt;script&gt;
(function(){
 var test = document.createElement('div');
 test.innerHTML = '&amp;nbsp;';
 test.className = 'adsbox';
  document.body.appendChild(test);
 window.setTimeout(function() {
  if (test.offsetHeight === 0) {
  alert("active");      
} else {
 alert("not active");
}
test.remove();
}, 100);
})();
</code></pre>

<p></p>

<p>This works fine so far.</p>

<p>Instead of display a alert message, I need a jquery popup. Therefore I changed the above code to:</p>

<pre><code>&lt;script&gt;
(function(){
 var test = document.createElement('div');
 test.innerHTML = '&amp;nbsp;';
 test.className = 'adsbox';
 document.body.appendChild(test);
 window.setTimeout(function() {
if (test.offsetHeight === 0) {
 showmessage();      
}
test.remove();
}, 100);
})();
&lt;/script&gt;
</code></pre>

<p>Without this function</p>

<pre><code>showmessage();   
</code></pre>

<p>works perfect. </p>

<p>When showmessage(); is inside this function, the popup doesnt come up. Instead the showmessage(); content is displayed on the website without css and not as a popup. I think this has something todo with the timeout function. But without this timeout, the detetection does not work in firefox.</p>

<p>Content from showmessage();</p>

<pre><code>function showmessage(){
document.write("&lt;div id=\"boxes\"&gt;");
document.write("  &lt;div id=\"dialog\" class=\"window\"&gt;");
document.write("  &lt;div style=\"display: none; opacity: 0.8;\" id=\"mask\"&gt;
&lt;\/div&gt;");
 document.write("&lt;\/div&gt;&lt;/div&gt;");

setTimeout(
function() {
    var id = '#dialog';

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});

    //transition effect     
    $('#mask').fadeIn(500); 
    $('#mask').fadeTo("slow",0.9);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    //$(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(1000);     

//if close button is clicked
$('.window .close').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();

    $('#mask').hide();
    $('.window').hide();
});     

//if mask is clicked
/*$('#mask').click(function () {
    $(this).hide();
    $('.window').hide();
});     */

}, 200);
}
</code></pre>

<p>Thank you very much</p>