Search code examples
javascriptadblock

Detect if a specific, out of site, javascript is blocked


We have a 3rd party script called from a different domain than ours. Some people use adblock and when the 3rd party rules are enabled, sometimes, this specific javascript library is blocked. Is there any way to detect, whether the javascript file was blocked from loading?

The file is updated regularly, so it's not an option to copy it to our domain and put a var hellomonkey = true; inside.


Solution

  • Generally speaking: No.

    You could attach load and error event listeners to the script element, but under normal circumstances they won't fire for cross origin requests. You can add a crossorigin attribute to change that, but only if the remote server gives you permission with CORS.

    Normally you can only tell if a script has loaded by looking for side effects (such as the creation of global variables or DOM elements) made by the script.