解决后删除 Recaptcha v2 有问题



我将Google Recaptcha v2添加到骨干视图中,如下所示:

// this is the callback function
var getRecaptchaResponse = function (response) {
if (response) {
thisView.captchaResponse = response;
thisView.canShowContinue();
} else {
alert("Captcha response was incorrect");
}
};
// render the recaptcha
var renderCaptcha = function () {
thisView.captchaWidgetId = grecaptcha.render('recaptcha-container', {
sitekey: GlobalSettings.recaptchaKey,
callback: getRecaptchaResponse,
size: 'compact'
});
};
// map the internal function to the window
// so that the callback registered in the 
// link below can be called by JSONP.
window.renderCaptcha = renderCaptcha;
// load the script
$.getScript('https://www.google.com/recaptcha/api.js?onload=renderCaptcha&render=explicit', function () { });

成功解决验证码后,我想将其从 UI 中删除,所以我只是删除div容器:

// if the user has solved the captcha yet, don't continue
if (!thisView.captchaResponse) {
return;
}
// remove recpatcha
$('#recaptcha-container').remove();

不过,谷歌似乎没有提供一种API方法来正确销毁grecaptcha小部件。这是个问题吗?推荐的方法是什么?

上述容器删除适用于 Chrome,但不适用于 IE11。在IE11中,验证码挑战仍然可见。

根据 reCAPTCHA 的常见问题解答,似乎在删除容器后,您应该使用以下grecaptcha.reset(id)重置验证码对象

https://developers.google.com/recaptcha/docs/faq

我收到一个未捕获的安全错误:阻止了具有原点的帧 "https://www.google.com"访问原点为 " 的帧。我该怎么办?

如果 reCAPTCHA 小部件 HTML 元素是 以编程方式删除最终用户单击后的某个时间 复选框。我们建议使用 grecaptcha.reset(( javascript 函数来重置重新验证码小部件。

最新更新