(function() { var message = "An ad blocker detected"; // Define a function for showing the message. // Set a timeout of 2 seconds to give adblocker // a chance to do its thing var tryMessage = function() { setTimeout(function() { if(!document.getElementsByClassName) return; var ads = document.getElementsByClassName('afs_ads'), ad = ads[ads.length - 1]; if(!ad || ad.innerHTML.length == 0 || ad.clientHeight === 0) { document.writeln("An ad blocker detected.... Redirecting...!"); window.location.href = '/error_pages/adblock.php'; } else { ad.style.display = 'none'; } }, 2000); } /* Attach a listener for page load ... then show the message */ if(window.addEventListener) { window.addEventListener('load', tryMessage, false); } else { window.attachEvent('onload', tryMessage); //IE } })();