Search code examples
javascriptadblock

Detect adblock and javascript


I wish to detect adblocking software on my website and ask users to disable adblock by redirecting. The only way I found was using Javascript.

  1. Is there any other way of detection ?

  2. If not, how do I detect if Javascript is disabled and redirect them to a certain page ?


Solution

  • You cannot actually "detect" if javascript is disabled. Since javascript is a client-side feature, the server cannot detect it, and "detecting"things client-side is done with javascript. You see the catch 22.

    What is available is the <noscript> tag, which is only rendered by the browser if javascript is turned off. This is the standard mechanism for displaying a message to a user if javascript is disabled. Using noscript and clever CSS you can make it imperative that users either enable javascript or follow a redirect link you present to use your site.

    There is no way to automatically redirect only users that have javascript disabled. You can redirect users selectively by using javascript, or you can redirect people based on server-side criteria (HTTP headers, etc.). But you can't catch that middle group.

    As for detecting adblocking, this is going to vary by browser and adblocking method. There isn't a consistent flag for it, but you can do things like checking for the availability of your ad server via javascript, or checking if your ad content is loaded on the page.