Recaptcha 2.0错误:reCAPTCHA占位符元素必须是元素或ID [英] Recaptcha 2.0 error: reCAPTCHA placeholder element must be an element or id

查看:254
本文介绍了Recaptcha 2.0错误:reCAPTCHA占位符元素必须是元素或ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了我能找到的所有其他帖子,但没有一个为我解决了这个问题。
我在文档头中有一个对ReCaptcha API的调用:

 < script src = https: //www.google.com/recaptcha/api.js?hl=he-IL&onload=onloadCallback&render=explicit type = text / javascript>< / script> 

然后紧接着

  var onloadCallback = function(){
grecaptcha.render( recaptcha2,{
sitekey: 6LendPIUAAAAAGQqB_2tq8fpgdGfBnEQA3v-CB0g,
主题: light
});
};

我在控制台中收到以下错误:

  recaptcha__iw.js:60未捕获(承诺)错误:reCAPTCHA占位符元素必须是mv上的元素或id 
(recaptcha__iw.js:60)
在Object.render(mootools-core.js:88)在onloadCallback处
(寄存器:56)

这是我的实时页面:
https://www.tofesyashir.co。 il / register



我尝试更改订单。我尝试在脚本调用中添加异步延迟,但没有任何帮助。



此外,非常奇怪的是,如果我手动调用grecaptcha.render,则会再次触发错误,即使我在页面中100%存在的ID上使用了它。出于某种原因,它根本不会在任何div上呈现。



你们怎么看?

解决方案

看一下您正在释放的异常的堆栈痕迹,实际上调用的 .render()方法是从mootools:

 未捕获(已承诺)错误:reCAPTCHA占位符元素必须是mv上的元素或id 
(recaptcha__iw .js:60)Object.render上的
(mootools-core.js:88)onloadCallback上的
(寄存器:56)

由于您使用的Mootools已缩小,因此我无法确切判断出哪里出了问题。但是,在我看来,好像是在该方法中进行了一些参数重新绑定,并且很可能以某种方式最终在reCaptcha方法最终被调用时,将其他内容分配给了第一个prepremeter。 p>

因此,我尝试从本地副本中删除网页中的mootools-确实可以解决问题,reCaptcha可以在mootools消失的情况下正常工作。



对此也有一个开放的错误报告: https://github.com。 com / google / recaptcha / issues / 376 。在那里提供的链接可导致在相关的buig中发布解决方案:手动更新mootools似乎可以解决该问题。


I've looked at every other post I could find, and none of them resolved the issue for me. I have a single call to the ReCaptcha API in my document head:

<script src="https://www.google.com/recaptcha/api.js?hl=he-IL&onload=onloadCallback&render=explicit" type="text/javascript"></script>

And then immediately after

var onloadCallback = function() {
    grecaptcha.render("recaptcha2", {
        sitekey: "6LendPIUAAAAAGQqB_2tq8fpgdGfBnEQA3v-CB0g",
        theme: "light"
    });
};

And I get the following error in my console:

recaptcha__iw.js:60 Uncaught (in promise) Error: reCAPTCHA placeholder element must be an element or id
    at mv (recaptcha__iw.js:60)
    at Object.render (mootools-core.js:88)
    at onloadCallback (register:56)

This is my live page: https://www.tofesyashir.co.il/register

I've tried changing the order. I've tried adding async defer to my script call, but nothing has helped.

Also, very strangely, if I manually call grecaptcha.render, the error is triggered again, even though I use it on IDs that 100% exist in the page. For some reason it won't render on any div at all.

What do you guys think?

解决方案

Looking at the stackm trace of the exception you're getting revelas, that the .render() method that actually gets called is from mootools:

Uncaught (in promise) Error: reCAPTCHA placeholder element must be an element or id
    at mv (recaptcha__iw.js:60)
    at Object.render (mootools-core.js:88)
    at onloadCallback (register:56)

Since the mootools you use is minified, I can't quite tell where exactly it goes wrong. However it looks to me as if some parameter re-binding is done in that method, and likely this causes something else to be assigned to the first apremeter when, in whatever way, in the end the reCaptcha method ends up getting called.

So I tried removing mootools from your webpage in a local copy - and it does indeed solve the issue, reCaptcha works fine with mootools gone.

There is also an open bug report for this: https://github.com/google/recaptcha/issues/376. A link provided there leads to a solution posted in a related buig: updating mootools manually seems to fix the issue.

这篇关于Recaptcha 2.0错误:reCAPTCHA占位符元素必须是元素或ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆