Ivan Orlov
Ivan Orlov

Reputation: 255

reCAPTCHA not showing after page refresh

Why is google reCaptcha2 (gReCaptcha) not showing after a page refresh,
but showing if page is reopened by the link?

See this video for explanation: http://take.ms/I2a9Z
Page url: https://orlov.io/signup

Page first open: captcha exists.
Navigate by link: captcha exists.
Open new browser tab: captcha exists.
Refreshing page by refresh icon, ctrl+R, ctrl+F5: captcha NOT exists.

I added body unload event to prevent browser cache, it did not help.

Browsers for testing:
Firefix 39.0
Chome: 44.0.2403.125 m
Opera: 30.0

In all browsers I get the same result. So does this mean there's an error on my side?

Upvotes: 2

Views: 6372

Answers (1)

Chloe
Chloe

Reputation: 26294

I think it has to do with the browser and the speed of your network. You are calling ReCaptcha with a callback, but you call it before you define the callback. Depending on your network speed or browser quirks, it might execute before the rest of the script has loaded.

Line 330:

<script src="//www.google.com/recaptcha/api.js?onload=renderReCaptchaCallback&amp;render=explicit&amp;hl=en-US" async defer></script>

Line 351:

<script type="text/javascript">if (typeof (renderReCaptchaCallback) === "undefined") {
    var reCaptchaWidgets = {};
    var renderReCaptchaCallback = function() {
        jQuery.each(reCaptchaWidgets, function(widgetId, widgetOptions) {
            grecaptcha.render(document.getElementById(widgetId), widgetOptions);
        });
    };
}</script>

So I would move the definition of renderReCaptchaCallback to the top of the page so it is defined well before trying to load it.

Upvotes: 1

Related Questions