【问题标题】:Re-captcha v3 integration验证码 v3 集成
【发布时间】:2019-04-03 20:45:32
【问题描述】:

我正在尝试整合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

【问题讨论】:

    标签: javascript captcha


    【解决方案1】:

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

    defer 属性将等待页面加载后再执行。

    所以删除延迟应该可以做到。

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

    【讨论】:

    • 我的脚本标签中没有 defer。这是我的样子:&lt;script src="https://www.google.com/recaptcha/api.js?render=myrecaptchakey"&gt;&lt;/script&gt;
    猜你喜欢
    • 2020-12-20
    • 2022-07-20
    • 1970-01-01
    • 2010-09-18
    • 2018-12-04
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多