return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - reference error: grecaptcha is undefined in chrome - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - reference error: grecaptcha is undefined in chrome - Stack Overflow

programmeradmin6浏览0评论

I have two captcha on same form. One on submit and other on a modal which will open after form submit. So I render it after reading many answer from here. Now it is working fine with mozilla but giving reference error in chrome.

My google api is:

<script src='.js'></script>

Then my code renders this in java script:

$('.g-recaptcha').each(function(index, el) {
        widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});

My html read like this

<div id="user_recaptcha" class="reCaptcha">
    <div id="e_Captcha" class="g-recaptcha" data-sitekey="<?php echo SITE_KEY; ?>" data-callback="recaptchaCallbackEvent"></div>
</div>

I declare widgetId at the top of my js.

I have two captcha on same form. One on submit and other on a modal which will open after form submit. So I render it after reading many answer from here. Now it is working fine with mozilla but giving reference error in chrome.

My google api is:

<script src='https://www.google./recaptcha/api.js'></script>

Then my code renders this in java script:

$('.g-recaptcha').each(function(index, el) {
        widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});

My html read like this

<div id="user_recaptcha" class="reCaptcha">
    <div id="e_Captcha" class="g-recaptcha" data-sitekey="<?php echo SITE_KEY; ?>" data-callback="recaptchaCallbackEvent"></div>
</div>

I declare widgetId at the top of my js.

Share Improve this question edited Nov 8, 2017 at 11:10 asked Nov 8, 2017 at 10:57 user4066420user4066420 1
  • Can u share some more of ur code so that I can get a better picture about it. Please add the html too. – Zac Commented Nov 8, 2017 at 11:05
Add a ment  | 

1 Answer 1

Reset to default 4

Recaptcha has a onload callback that will run once recaptcha is loaded. Place your code inside that callback function.

https://developers.google./recaptcha/docs/display

//call this function in your js
function onloadCallback() {
    $('.g-recaptcha').each(function(index, el) {
        widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
    });
}

//load this script before your js is loading
<script src="https://www.google./recaptcha/api.js?onload=onloadCallback&render=explicit"></script>
//your html is absolutely fine.
发布评论

评论列表(0)

  1. 暂无评论