Rob*_*ard 5 javascript recaptcha invisible-recaptcha
在我的网页中,我通过调用函数来验证基于 Invisible Recaptcha 的表单grecaptcha.execute()。通常这种情况对于用户来说是不可见的;他们看到的只是grecaptcha验证完成后触发的表单提交。
有时,会触发不那么隐形的验证码行为(例如,如果用户行为可疑),并向用户显示他们必须解决的常规验证码。当发生这种情况时,我想以编程方式检测它。
是否可以以编程方式发现在调用后是否向用户显示验证码grecaptcha.execute()?
到目前为止,我已经尝试使用MutationEvents和来观察 DOM MutationObservers。不幸的是,所有有趣的事情都发生在 an 内部iframe,似乎无法判断是否显示了完整的验证码。
我不想测量调用grecaptcha我给它的回调需要多长时间,因为那是不可靠的(例如,缓慢的移动连接会扭曲结果)。
标记:
<form id="form" method="post" action="/form">
Name: (required) <input id="name" name="name">
<div id="g-recaptcha-div"
class="g-recaptcha"
data-sitekey="keeeey"
data-callback="onRecaptchaDone"
data-size="invisible"></div>
<button id="thebutton">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
代码:
function onSubmit(event) {
event.preventDefault();
grecaptcha.reset();
grecaptcha.execute();
}
function onRecaptchaDone(token) {
form.submit();
}
window.onload = function() {
form.onsubmit = onSubmit;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2156 次 |
| 最近记录: |