WordPress.org

Support

Support » Plugins and Hacks » JavaScript error with AdBlock disrupting the rest of the website

JavaScript error with AdBlock disrupting the rest of the website

  • radgh
    Participant

    @radgh

    (NOTE: I solved this myself, I guess this is more of a bug report?)

    If your visitors are running adblock, the adrotate plugin will throw an error that the function “jQuery().gslider” is undefined. Obviously this is because the dependency is being blocked by the adblock plugin, but there is no failsafe in case that script fails to load.

    If they get this error, it seems all other scripts loaded afterwards will not run either.

    There isn’t a filter to let me fix this using functions.php, so I had to modify the plugin source code directly. That’s why I’m posting here, hopefully this gets added to the next version so I do not have the “hack” the plugin again.

    The fix is below and is very straightforward, it just checks that the “gslider” function is not defined before calling it.

    adrotate-output.php
    line 557

    $array_js[] = "\tif ( typeof jQuery('body').gslider != 'undefined' ) jQuery('.g-".$group->id."').gslider({ groupid: ".$group->id.", speed: ".$group->adspeed." });\n";

    https://wordpress.org/plugins/adrotate/

  • The topic ‘JavaScript error with AdBlock disrupting the rest of the website’ is closed to new replies.