2017-08-09 21 views
1

我加入谷歌的v2的的Recaptcha有问题像这样一个骨干视图:删除的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() { }); 

一旦Captcha验证码被成功地解决了我想从用户界面中删除它,所以我“M简单地移除div容器:

// if the user has solved the captcha yet, don't continue 
if (!thisView.captchaResponse) { 
    return; 
} 

// remove recpatcha 
$('#recaptcha-container').remove(); 

似乎没有要,谷歌已经提供给摧毁grecaptcha部件虽然一个正确API method。这是一个问题吗?推荐的方法是什么?

以上移除的容器在Chrome中运行,但不在IE11中运行。在IE11中,验证码挑战仍然可见。

+0

您的意思是编程验证码对象? – Ezenhis

+0

@Ezenhis正好。我正在寻找'grecaptcha.remove('recaptcha-container');'或者其他类似的东西。 – Junto

回答

1

按照验证码的常见问题,似乎移出容器后,你应该重新使用grecaptcha.reset(id)

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

I'm getting an uncaught SecurityError: blocked a frame with origin " https://www.google.com " from accessing a frame with origin "". What should I do?

This typically occurs if the reCAPTCHA widget HTML element is programmatically removed sometime after the end user clicks on the checkbox. We recommend using the grecaptcha.reset() javascript function to reset the reCAPTCHA widget.

+0

我没有收到任何错误,但现在可以解决问题。取出容器并调用reset()后,验证屏幕现在消失。谢谢。 – Junto

+0

我知道,我只是想保持“这通常发生[...]”在报价中的上下文;)很高兴帮助:) – Ezenhis

+0

我注意到,在Chrome中,不需要重置,而是抛出一个Javascript错误,但在IE中是必需的。所以我现在有一个检查,看看它是否是IE浏览器,只有运行该重置。 – Junto