Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reload ReCaptcha using JavaScript?

People also ask

How do I restart Captcha?

The issue can be corrected by using the "Unlock CAPTCHA" tool from Google. Visit the Unlock CAPTCHA page (see link in Resources) and then click "Continue." A new page will appear titled "Next Step." Sign in using your email application when Google prompts you.

How long does it take for reCAPTCHA to reset?

Note: reCAPTCHA tokens expire after two minutes. If you're protecting an action with reCAPTCHA, make sure to call execute when the user takes the action rather than on page load. You can execute reCAPTCHA on as many actions as you want on the same page.

How do I reset reCAPTCHA v3?

reCAPTCHA v3 reset grecaptcha. execute('[Your recaptcha ID]', { action: 'general_form_contact_us' }). then(function(token) { document.


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.)


If you are using version 1

Recaptcha.reload();

If you are using version 2

grecaptcha.reset();

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/display#js_api


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)


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();
    }

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.