Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Loads current ReCaptcha version using an intelligent import and a <div>
/**
* Usage:
* - import jQuery;
* - import this;
* - create an element (maybe a div) with id="js-reCaptchaContainer" and data-publickey="<your public key>"
* ex: <div id="js-reCaptchaContainer" data-publickey="6LfSXd4SAAAAAH0wvCuC164"></div>
*/
if (this.jQuery) {
jQuery(document).ready(function ($) {
var el = $('#js-reCaptchaContainer');
if (el.length && el.data('publickey')) {
$.ajax({
url: "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js",
dataType: "script",
cache: true
}).done(function (script, textStatus) {
Recaptcha.create(el.data('publickey'), "js-reCaptchaContainer", {
theme: "clean",
lang: "pt",
callback: Recaptcha.focus_response_field
});
}).fail(function (jqxhr, settings, exception) {
// fail message
});
}
});
} else {
alert('Recaptcha loader requires jQuery');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment