{"id":1682,"date":"2021-06-09T13:26:00","date_gmt":"2021-06-09T10:26:00","guid":{"rendered":"https:\/\/html-online.com\/articles\/?p=1682"},"modified":"2026-03-09T15:38:44","modified_gmt":"2026-03-09T13:38:44","slug":"how-to-detect-adblockers-with-javascript","status":"publish","type":"post","link":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/","title":{"rendered":"How to Detect AdBlockers with JavaScript"},"content":{"rendered":"<p>The struggle between advertisers and those who resist seeing ads has been going on for some time now. While ad-blockers have become more popular, so have anti-ad blockers. It is nearly impossible to render ad blockers invisible to blogs that display anti-ad blocking messages. It is also impossible for publishers to make their websites immune to these tools.<\/p>\n<p class=\"aligncenter\"><img decoding=\"async\" src=\"\/articles\/wp-content\/uploads\/2021\/12\/abp-detector.jpg\" alt=\"detect adblocker javascript\" \/><br \/>\n<em>AdBlocker warning popup <a href=\"https:\/\/edition.cnn.com\/\" target=\"_blank\" rel=\"nofollow external noopener\">on CNN<\/a><\/em><\/p>\n<p><!--more--><\/p>\n<p>We have <a href=\"\/articles\/detect-adblock-javascript\/\">already published an article<\/a> on this topic but that has become outdated. The code presented has stopped working and it was time for an update.<strong> Adblockers, just as anti adblockers keep evolving, adapting to each other.<\/strong><\/p>\n<h2>What is an AdBlocker?<\/h2>\n<p>AdBlocker is an effective tool for blocking advertisements on websites, as it disables the ads in particular web pages by blocking specific scripts and DOM elements. It is a widespread method of filtering out unwanted content, as it prevents ads from displaying on pages or even entire domains. In other words, AdBlocker prevents online marketers from making money off of advertisements that may be inappropriate for specific audiences or out of context with the website&#8217;s intended purpose.<\/p>\n<p class=\"aligncenter\"><img decoding=\"async\" src=\"\/articles\/wp-content\/uploads\/2021\/12\/disable-adblock.jpg\" alt=\"disable adblock\" \/><br \/>\n<em>Ad blockers can be easily disabled on sites you wish to support<\/em><\/p>\n<p><a href=\"https:\/\/www.google.com\/adsense\/start\/\" target=\"_blank\" rel=\"nofollow external noopener\">Google AdSense<\/a> (Google&#8217;s advertising platform) uses a <a href=\"\/articles\/category\/javascript\/\">JavaScript<\/a>-based domain to collect ad space from the publisher and fill it with advertisements, creating revenue for the publisher. An AdBlocker is any software program that will disable this. In a perfect world, an adblocker would block all scripts that are associated with Google&#8217;s AdSense, effectively stopping ads from displaying on as many sites as possible. And imagine a lucrative ad to buy BNB\u00a0being missed out just because AdBlock is in place. That&#8217;s undoubtedly a loss for advertisers and publishers alike.<\/p>\n<h2>Popular names in the AdBlock industry<\/h2>\n<p>As with almost any other business on the planet, ad blockers are plenty but not many make it to the top. Here are the top 5 AdBlock extensions.<\/p>\n<ul>\n<li><strong>AdBlock Plus (ABP)<\/strong> &#8211; ABP is available for Firefox, Chrome, Safari, Edge, and Opera. On top of that, it enables many whitelists and blacklists to be inserted, for full customization.<\/li>\n<li><strong>AdBlock<\/strong> &#8211; probably the second-best application. It doesn&#8217;t support Opera but it is still one of the most downloaded ad blockers in the world.<\/li>\n<li><strong>PoperBlocker<\/strong> &#8211; unlike the others in the list, it is more like a complementary tool.<\/li>\n<li><strong>air AdBlocker<\/strong> &#8211; it is a fast and light plugin. However, it is supported only on Chrome.<\/li>\n<li><strong>uBlock Origin<\/strong> &#8211; low resource overhead is among the top reasons why this app is used. Yet again, it is available only on Chrome and Firefox.<\/li>\n<\/ul>\n<h2>How do advertisers and publishers lose money from AdBlock?<\/h2>\n<p><a href=\"https:\/\/disableadblock.com\/#how2disable\" target=\"_blank\" rel=\"nofollow external noopener\"><img decoding=\"async\" class=\"alignright\" src=\"\/articles\/wp-content\/uploads\/2017\/11\/disable-adblock.jpg\" alt=\"disable adblock warning\" \/><\/a>According to reports, publishers have lost up to $78 billion in 2020 alone.<\/p>\n<p>Adblocking is a more pervasive threat to publishers than ever before, with new forms of technology cropping up every year. Ad blockers and users with ad-blocker plug-ins are affecting revenue and user experience at an alarming rate. There are many reasons for this phenomenon, including a declining trust in advertisements and marketing campaigns.<\/p>\n<p class=\"aligncenter\"><iframe loading=\"lazy\" style=\"width: 300px; height: 200px; overflow: hidden;\" src=\"https:\/\/disableadblock.com\/widget\/thief\/\" width=\"300\" height=\"300\" scrolling=\"no\">Iframes not supported<\/iframe><\/p>\n<p>Let&#8217;s assume a publisher has about 1 million page views within a month, an average <a href=\"https:\/\/www.marketingterms.com\/dictionary\/ecpm\/\" target=\"_blank\" rel=\"nofollow external noopener\">eCPM<\/a> of $3, an ad density of 3, and an ad block rate of 40%. In that case, the revenue loss can be calculated as (40\/100)*(1000000*3*3\/1000) = $3,600\/month or $43,200 for just one year.<\/p>\n<h3>Numbers game:<\/h3>\n<p>According to BusyBudgeter, blogging can become a full-time job if a website receives about 100,000 page views a month. So, in the case we mentioned, 1m page views is an average for a decent agency. In most case scenarios, huge websites have between 10 and 100 million page views per month.<\/p>\n<h2>How to detect AdBlocking software?<\/h2>\n<p>By adding an identifier, it&#8217;s possible to identify if a user is using an adblocker. By forcing another element to be rendered, it&#8217;s possible to know if a user with an adblocker is on the page. This can help us identify users who are blocking our ads to reach out to them and offer a solution.<\/p>\n<h3>Method 1:<\/h3>\n<p>Step 1: Create an HTML file and name it as <strong>detect_adblocker.html<\/strong><\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">html<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">type<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"text\/javascript\"<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t\tvar\u00a0adblock <span style=\"color: #808030;\">=<\/span> <span style=\"color: #0f4d75;\">true<\/span><span style=\"color: #800080;\">;<\/span>\n\t<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">type<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"text\/javascript\"<\/span><span style=\"color: #274796;\">\u00a0<\/span><span style=\"color: #074726;\">src<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"adframe.js\"<\/span><span style=\"color: #a65700;\">&gt;<\/span><span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">type<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"text\/javascript\"<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t\t<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>adblock<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\t\t\t<span style=\"color: #800000; font-weight: bold;\">alert<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Please disable your AdBlocker<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\t\t\tdocument<span style=\"color: #808030;\">.<\/span>getElementById<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">wrapper<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">.<\/span>style<span style=\"color: #808030;\">.<\/span>display<span style=\"color: #808030;\">=<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">none<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #800080;\">;<\/span>\n\t\t<span style=\"color: #800080;\">}<\/span>\n\t<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">body<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">div<\/span> <span style=\"color: #074726;\">id<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"wrapper\"<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">p<\/span><span style=\"color: #a65700;\">&gt;<\/span>Your Page<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">p<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">div<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">body<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">html<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<p>Step 2: Create a js. file and define scripting for adblocker. In this step we create a variable called &#8220;AdBlock&#8221; and set it to true. Then, we add the <strong>adframe.js<\/strong> file.<\/p>\n<p>The AdBlock works in a very simple manner. It detects any external file which has &#8216;ad&#8217; or shows an advertisement inside its name or path, and blocks that file from running on the webpage.<\/p>\n<pre>var\u00a0adblock <span style=\"color: #808030;\">=<\/span> <span style=\"color: #0f4d75;\">true<\/span><span style=\"color: #800080;\">;<\/span><\/pre>\n<h3><span style=\"color: inherit; font-family: inherit; font-size: 25px;\">Method 2:<\/span><\/h3>\n<p>When you call this code and if the value of Adblock is false then the AdBlock is not installed or disabled. If it is true then the AdBlock is installed and enabled.<\/p>\n<p>Set up a bait. If this code is caught, it will 100% be detected by AdBlock software.<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">div<\/span> <span style=\"color: #074726;\">class<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"banner_ad\"<\/span><span style=\"color: #a65700;\">&gt;<\/span> <span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">div<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<p>Basic ad detection code simply accesses the bait element to perform basic tests, then identifies if the height and width are set by default to zero or display: none. The following JavaScript checks for this scenario.<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">src<\/span><span style=\"color: #808030;\">=<\/span>\n<span style=\"color: #0000e6;\">\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.12.0\/jquery.min.js\"<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\tvar\u00a0detector <span style=\"color: #808030;\">=<\/span> <span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\t\t<span style=\"color: #800000; font-weight: bold;\">setTimeout<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">function<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\t\t\t<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">!<\/span>document<span style=\"color: #808030;\">.<\/span>getElementsByClassName<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800000; font-weight: bold;\">return<\/span><span style=\"color: #800080;\">;<\/span>\n\t\t\tvar\u00a0ads <span style=\"color: #808030;\">=<\/span>\n\t\t\tdocument<span style=\"color: #808030;\">.<\/span>getElementsByClassName<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">banner_ad<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span>\n\t\t\tad <span style=\"color: #808030;\">=<\/span> ads<span style=\"color: #808030;\">[<\/span>ads<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">length<\/span> <span style=\"color: #808030;\">-<\/span> <span style=\"color: #008c00;\">1<\/span><span style=\"color: #808030;\">]<\/span><span style=\"color: #800080;\">;<\/span>\n\n\t\t\t<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">!<\/span>ad <span style=\"color: #808030;\">||<\/span> ad<span style=\"color: #808030;\">.<\/span>innerHTML<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">length<\/span> <span style=\"color: #808030;\">==<\/span> 0\u00a0\n\t\t\t<span style=\"color: #808030;\">||<\/span> ad<span style=\"color: #808030;\">.<\/span>clientHeight <span style=\"color: #808030;\">===<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\t\t\t\tconsole<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">log<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">Ad Blocker Detected<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\t\t\t<span style=\"color: #800080;\">}<\/span> else\u00a0<span style=\"color: #800080;\">{<\/span>\n\t\t\t\tconsole<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">log<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">No Ad Blocker<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\t\t\t<span style=\"color: #800080;\">}<\/span>\n\t\t<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">2000<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\t<span style=\"color: #800080;\">}<\/span>\n\t<span style=\"color: #696969;\">\/* Add a page load listener *\/<\/span>\n\t<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>window<span style=\"color: #808030;\">.<\/span>addEventListener<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\n\t\twindow<span style=\"color: #808030;\">.<\/span>addEventListener<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">load<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">,<\/span> detector<span style=\"color: #808030;\">,<\/span> <span style=\"color: #0f4d75;\">false<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\t<span style=\"color: #800080;\">}<\/span>\n\t<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<p>In order to set it up successfully, you need to include the following passage:<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">html<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\t<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">title<\/span><span style=\"color: #a65700;\">&gt;<\/span>Page Detector<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">title<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">head<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">body<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">h1<\/span><span style=\"color: #a65700;\">&gt;<\/span>TEST<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">h1<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<h3>Method 3:<\/h3>\n<p>For those looking for a robust and comprehensive detection option, the <strong>BlockAdBlock<\/strong> script is an alternative that is well-regarded within the web publisher community for its ability to detect AdBlock users automatically. Details of this script and download instructions are available at the following URL: <a href=\"https:\/\/github.com\/sitexw\/BlockAdBlock\" target=\"_blank\" rel=\"nofollow external noopener\">https:\/\/github.com\/sitexw\/BlockAdBlock<\/a><\/p>\n<p>To perform BlockAdBlock, download the <strong>blockadblock.js<\/strong> file from the web page mentioned above, and install it onto your server. Next, add the following to each web page for which detection is required:<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span> <span style=\"color: #074726;\">src<\/span><span style=\"color: #808030;\">=<\/span><span style=\"color: #0000e6;\">\"\/blockadblock.js\"<\/span><span style=\"color: #a65700;\">&gt;<\/span><span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n\n<span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #696969;\">\/\/ Function called if AdBlock is not detected<\/span>\nfunction\u00a0adBlockNotDetected<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\nconsole<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">log<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">Ad Blocker Detected<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n\n<span style=\"color: #800080;\">}<\/span>\n<span style=\"color: #696969;\">\/\/ Function called if AdBlock is detected<\/span>\nfunction\u00a0adBlockDetected<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\nconsole<span style=\"color: #808030;\">.<\/span><span style=\"color: #800000; font-weight: bold;\">log<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">No Ad Blocker<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n<span style=\"color: #800080;\">}<\/span>\n\n<span style=\"color: #696969;\">\/\/ Recommended audit because AdBlock locks the file 'blockadblock.js'<\/span>\n<span style=\"color: #696969;\">\/\/ If the file is not called, the variable does not exist 'blockAdBlock'<\/span>\n<span style=\"color: #696969;\">\/\/ This means that AdBlock is present<\/span>\n<span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>typeof\u00a0blockAdBlock <span style=\"color: #808030;\">===<\/span> <span style=\"color: #800000;\">'<\/span><span style=\"color: #0000e6;\">undefined<\/span><span style=\"color: #800000;\">'<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #800080;\">{<\/span>\nadBlockDetected<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n<span style=\"color: #800080;\">}<\/span> else\u00a0<span style=\"color: #800080;\">{<\/span>\nblockAdBlock<span style=\"color: #808030;\">.<\/span>onDetected<span style=\"color: #808030;\">(<\/span>adBlockDetected<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\nblockAdBlock<span style=\"color: #808030;\">.<\/span>onNotDetected<span style=\"color: #808030;\">(<\/span>adBlockNotDetected<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n<span style=\"color: #800080;\">}<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<p>Rather than relying on a simple script to block AdBlock, BlockAdBlock goes the extra mile to ensure that ads are not blocked and includes a number of configuration options for more control over the blocking and detection process. The added functionality and increased control are made possible by using a configuration file, which allows users to customize the script to their particular application needs.<\/p>\n<pre style=\"color: #000000; background: #ffffff;\">blockAdBlock<span style=\"color: #808030;\">.<\/span>setOption<span style=\"color: #808030;\">(<\/span><span style=\"color: #800080;\">{<\/span>\n  debug<span style=\"color: #800080;\">:<\/span> <span style=\"color: #0f4d75;\">true<\/span><span style=\"color: #808030;\">,<\/span>\n  checkOnLoad<span style=\"color: #800080;\">:<\/span> <span style=\"color: #0f4d75;\">false<\/span>\n<span style=\"color: #800080;\">}<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\n<\/pre>\n<p>When <em>checkOnLoad<\/em> option is set to false, the detection can be triggered separately from everywhere within the web page via a call to the <em>blockAdBlock.check()<\/em> function as follows:<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #a65700;\">&lt;<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<span style=\"color: #808030;\">.<\/span>\n<span style=\"color: #808030;\">.<\/span>\n\nblockAdBlock<span style=\"color: #808030;\">.<\/span>check<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\n<span style=\"color: #808030;\">.<\/span>\n<span style=\"color: #808030;\">.<\/span>\n<span style=\"color: #a65700;\">&lt;\/<\/span><span style=\"color: #800000; font-weight: bold;\">script<\/span><span style=\"color: #a65700;\">&gt;<\/span>\n<\/pre>\n<h2>Summary<\/h2>\n<p>Ad blockers have taken a lot of flak for ruining websites. Unfortunately, it\u2019s one or the other. Publishers are dependent on revenue from ads to survive, so if people use ad blockers, then they can&#8217;t view the content. On the other hand, readers should not be bombarded with ads because there is a high chance they will leave the website and never visit it again. This is why you should find a balance. Keep your ad policy fair with your customers and you will be rewarded with their trust.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The struggle between advertisers and those who resist seeing ads has been going on for some time now. While ad-blockers have become more popular, so have anti-ad blockers. It is nearly impossible to render ad blockers invisible to blogs that display anti-ad blocking messages. It is also impossible for publishers to make their websites immune &hellip; <a href=\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Detect AdBlockers with JavaScript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5,8],"tags":[],"class_list":["post-1682","post","type-post","status-publish","format-standard","hentry","category-freebies","category-javascript","category-tools"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Detect AdBlockers with JavaScript - HTML Online<\/title>\n<meta name=\"description\" content=\"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Detect AdBlockers with JavaScript - HTML Online\" \/>\n<meta property=\"og:description\" content=\"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Online\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/htmlcoding\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-09T10:26:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-09T13:38:44+00:00\" \/>\n<meta name=\"author\" content=\"HTML Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HTML Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\"},\"author\":{\"name\":\"HTML Editor\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\"},\"headline\":\"How to Detect AdBlockers with JavaScript\",\"datePublished\":\"2021-06-09T10:26:00+00:00\",\"dateModified\":\"2026-03-09T13:38:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\"},\"wordCount\":1117,\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"articleSection\":[\"Freebies\",\"JavaScript\",\"Tools\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\",\"url\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\",\"name\":\"How to Detect AdBlockers with JavaScript - HTML Online\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/#website\"},\"datePublished\":\"2021-06-09T10:26:00+00:00\",\"dateModified\":\"2026-03-09T13:38:44+00:00\",\"description\":\"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.\",\"breadcrumb\":{\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/html-online.com\/articles\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Detect AdBlockers with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/html-online.com\/articles\/#website\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"name\":\"HTML Online Articles\",\"description\":\"Tips, tricks, tutorials\u2026\",\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/html-online.com\/articles\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/html-online.com\/articles\/#organization\",\"name\":\"HTML Online\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"contentUrl\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"width\":350,\"height\":350,\"caption\":\"HTML Online\"},\"image\":{\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/htmlcoding\/\",\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\",\"name\":\"HTML Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"caption\":\"HTML Editor\"},\"description\":\"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/@htmlg\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Detect AdBlockers with JavaScript - HTML Online","description":"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/","og_locale":"en_GB","og_type":"article","og_title":"How to Detect AdBlockers with JavaScript - HTML Online","og_description":"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.","og_url":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/","og_site_name":"HTML Online","article_publisher":"https:\/\/www.facebook.com\/htmlcoding\/","article_published_time":"2021-06-09T10:26:00+00:00","article_modified_time":"2026-03-09T13:38:44+00:00","author":"HTML Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HTML Editor","Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#article","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/"},"author":{"name":"HTML Editor","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d"},"headline":"How to Detect AdBlockers with JavaScript","datePublished":"2021-06-09T10:26:00+00:00","dateModified":"2026-03-09T13:38:44+00:00","mainEntityOfPage":{"@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/"},"wordCount":1117,"publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"articleSection":["Freebies","JavaScript","Tools"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/","url":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/","name":"How to Detect AdBlockers with JavaScript - HTML Online","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/#website"},"datePublished":"2021-06-09T10:26:00+00:00","dateModified":"2026-03-09T13:38:44+00:00","description":"Ad blockers are terrible for publishers. They limit their ad exposures, thus costing them money. How to detect ad blockers with Javascript.","breadcrumb":{"@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/html-online.com\/articles\/how-to-detect-adblockers-with-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/html-online.com\/articles\/"},{"@type":"ListItem","position":2,"name":"How to Detect AdBlockers with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/html-online.com\/articles\/#website","url":"https:\/\/html-online.com\/articles\/","name":"HTML Online Articles","description":"Tips, tricks, tutorials\u2026","publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/html-online.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/html-online.com\/articles\/#organization","name":"HTML Online","url":"https:\/\/html-online.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","contentUrl":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","width":350,"height":350,"caption":"HTML Online"},"image":{"@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/htmlcoding\/","https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww"]},{"@type":"Person","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d","name":"HTML Editor","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","caption":"HTML Editor"},"description":"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.","sameAs":["https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/@htmlg"]}]}},"_links":{"self":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/1682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/comments?post=1682"}],"version-history":[{"count":3,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/1682\/revisions"}],"predecessor-version":[{"id":2553,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/1682\/revisions\/2553"}],"wp:attachment":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/media?parent=1682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/categories?post=1682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/tags?post=1682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}