N
N
Nubbin2017-09-26 11:32:12
JavaScript
Nubbin, 2017-09-26 11:32:12

Recaptcha disappears after page refresh?

Good afternoon, I still can’t understand why recaptcha v2 disappears after refreshing the page.

<script type="text/javascript">
        var onloadCallback = function() {
            grecaptcha.render('html_element', {
                'sitekey' : '6*****'
            });
        };
    </script>


<div id="html_element"></div>


<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>
</script>


The first time it outputs well, but when you refresh the page, this is what comes out:

Uncaught Error: ReCAPTCHA placeholder element must be an element or id

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya Gerasimov, 2017-09-26
@Nubbin

Script loaded, DOM not rendered
Need to catch the moment when recaptcha loads and DOMContentLoaded

A
Anton, 2017-12-14
@Eridani

I met with the same problem, moreover, on one page 3 recaptchas are loaded without problems in different places of the HOME, and on one page it categorically refused to load into one of the forms, although everything looks fine with loading.
I had to set a settimeout

setTimeout(function() {
    captcha4 = grecaptcha.render(document.getElementById('feedbackc'), {
    'sitekey' : mysitekey
    });
  }, 1000)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question