繁体   English   中英

重新验证 v3 集成

[英]Re-captcha v3 integration

我正在尝试集成reCaptcha V3

我试过的是:

<script defer="defer"
        type="text/javascript"
        src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=6Lda2XgUAAAAAKxRqwe9zBL09zv2ja1DYV-r">
</script>
<script type="text/javascript">
    var onloadCallback = function(){
        grecaptcha.execute('6Lda2XgUAAAAAKxRaqwev2ja1DYV-r', {action: '/foo/bar/'}).then(function(token) {
            alert(token)
        });
    };
</script>

但是在加载页面上我得到(index):1 Uncaught (in promise) null有人知道原因吗,我该如何解决?

编辑:我发现了这个错误:

Uncaught TypeError: grecaptcha.execute(...).then(...).catch is not a function
    at onloadCallback ((index):18)
    at gf (recaptcha__pl.js:512)
    at Gj (recaptcha__pl.js:508)
    at recaptcha__pl.js:520
    at recaptcha__pl.js:539
onloadCallback @ (index):18
gf @ recaptcha__pl.js:512
Gj @ recaptcha__pl.js:508
(anonymous) @ recaptcha__pl.js:520
(anonymous) @ recaptcha__pl.js:539
(index):1 Uncaught (in promise) null

grecaptcha.execute 在第一个脚本中创建

defer 属性将在执行之前等待页面加载。

所以删除 defer 应该可以。

注意:defer 没有出现在官方集成文档中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM