How to Reload ReCaptcha using JavaScript?

前端 未结 10 575
情深已故
情深已故 2020-12-07 09:58

I have a signup form with AJAX so that I want to refresh Recaptcha image anytime an error is occured (i.e. username already in use).

I am looking for a code compatib

相关标签:
10条回答
  • 2020-12-07 10:24

    Important: Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0.

    You can use grecaptcha.reset(); to reset the captcha.

    Source : https://developers.google.com/recaptcha/docs/verify#api-request

    0 讨论(0)
  • 2020-12-07 10:30

    For reCaptcha v2, use:

    grecaptcha.reset();
    

    If you're using reCaptcha v1 (probably not):

    Recaptcha.reload();
    

    This will do if there is an already loaded Recaptcha on the window.

    (Updated based on @SebiH's comment below.)

    0 讨论(0)
  • 2020-12-07 10:35

    If you are using Version 1.0 of the reCAPTCHA API, please upgrade to Version 2.0 (Version 1.0 is no longer supported)

    Use grecaptcha.reset(); to reset the captcha.

    0 讨论(0)
  • 2020-12-07 10:36

    Try this

    <script type="text/javascript" src="//www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
    <script type="text/javascript">
              function showRecaptcha() {
                Recaptcha.create("YOURPUBLICKEY", 'captchadiv', {
                  theme: 'red',
                  callback: Recaptcha.focus_response_field
                });
              }
     </script>
    
    <div id="captchadiv"></div>
    

    If you calll showRecaptcha the captchadiv will be populated with a new recaptcha instance.

    0 讨论(0)
  • 2020-12-07 10:39
    grecaptcha.reset(opt_widget_id)
    

    Resets the reCAPTCHA widget. An optional widget id can be passed, otherwise the function resets the first widget created. (from Google's web page)

    0 讨论(0)
  • 2020-12-07 10:39

    Or you could just simulate a click on the refresh button

    // If recaptcha object exists, refresh it
        if (typeof Recaptcha != "undefined") {
          jQuery('#recaptcha_reload').click();
        }
    
    0 讨论(0)
提交回复
热议问题