Javascript ReCaptcha v2 客户端事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31687803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ReCaptcha v2 client side events
提问by QFDev
Does ReCaptcha v2expose any client side events? I am looking specifically to identify when the Captcha response has been returned once the box is ticked, so I can reveal the "Continue" button below.
ReCaptcha v2是否公开任何客户端事件?我正在专门确定在勾选框后何时返回 Captcha 响应,以便我可以显示下面的“继续”按钮。
Without this it is possible for the user to click the checkbox then quickly click the submit button before the captcha response is back.
如果没有这个,用户可以单击复选框,然后在验证码响应返回之前快速单击提交按钮。
I could possible add my own click event handler to the class recaptcha-checkbox-checkmark
and poll the visiblity of the tick, I just wondered if there was a simpler way to do this?
我可以将自己的点击事件处理程序添加到类中recaptcha-checkbox-checkmark
并轮询刻度的可见性,我只是想知道是否有更简单的方法来做到这一点?
$(".recaptcha-checkbox-checkmark").click(function() {
//...Poll for visibility of tick
});
采纳答案by Aaron
You can configure reCAPTCHA to give a callback on successful validation using the data-callback attribute on the g-recaptcha tag or via the 'callback' parameter if using explicit rendering.
您可以将 reCAPTCHA 配置为使用 g-recaptcha 标签上的 data-callback 属性或通过“callback”参数(如果使用显式渲染)在成功验证时提供回调。
See https://developers.google.com/recaptcha/docs/display#render_param
请参阅 https://developers.google.com/recaptcha/docs/display#render_param
Example using explicit rendering:
使用显式渲染的示例:
var myCallback = function(val) { console.log(val); };
grecaptcha.render(
document.getElementsById('my-recaptcha-placeholder'),
{
callback: myCallback,
sitekey: mySiteKey
});
回答by Linus Oleander
Another solution is to set data-callback
directly on the g-recaptcha
div, like this
另一种解决方法是data-callback
直接在g-recaptcha
div上设置,像这样
<script type="text/javascript">
var imNotARobot = function() {
console.info("Button was clicked");
};
</script>
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="key"></div>