Search code examples
javascriptjqueryrecaptcha

jQuery window onload not fired when using Recaptcha


I have noticed a strange issue that when using Googles recaptcha, the jQuery $(window).on("load", function (e) { event wont fire ($(document).ready(function () { or window.addEventListener('load', function () { won't fire as well). When I reload the page using F5 it works as intendet. I noticed that a recaptcha network request is cancelled, see the attached image. When I reload the page the request doesn't fail.

Network Requests


Solution

  • I found a workaround: When I load the recaptcha js via ajax (see below), the event handlers fire on the initial page load.

    $.getScript( "https://www.google.com/recaptcha/api.js");