Automatically bind the challenge to a button

The easiest method for using the invisible reCAPTCHA widget on your page is to include the necessary JavaScript resource and add a few attributes to your html button. The necessary attributes are a class name ‘g-recaptcha’, your site key in the data-sitekey attribute, and the name of a JavaScript callback to handle completion of the captcha in the data-callback attribute.

The script must be loaded using the HTTPS protocol and can be included from any point on the page without restriction.
Programmatically bind the challenge to a button or invoke the challenge.

Deferring the binding can be achieved by specifying your onload callback function and adding parameters to the JavaScript resource. This works the same as the normal reCAPTCHA challenge.
Programmatically invoke the challenge.

Invoking the reCAPTCHA verification programmatically can be achieved by rendering the challenge in a div with an attribute data-size=’invisible’ and programmatically calling execute.

When your callback is executed, you can call the grecaptcha.render method from the Javascript API.

Note: your onload callback function must be defined before the reCAPTCHA API loads. To ensure there are no race conditions:

order your scripts with the callback first, and then reCAPTCHA
use the async and defer parameters in the script tags