Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google ReCAPTCHA onload callback not firing

I can't for the life of me figure out what I'm doing wrong here. The loaded() callback should fire but does not. Here's the code for a reduced test case (with a JS fiddle link below):

<script>
  function loaded() {
    alert('loaded() triggered.');
  }
</script>

<script src="https://www.google.com/recaptcha/api.js?onload=loaded" async defer></script>

https://jsfiddle.net/48dshrew/

ReCaptcha Documentation

like image 260
Andrew Aponte Avatar asked Apr 03 '17 14:04

Andrew Aponte


1 Answers

Looks like the render mode needs to be set to 'explicit' for reCaptcha to call your custom onload callback function. Try this:

var onloadCallback = function() {
     console.log('loaded() triggered.');
}
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>
</script>
like image 119
Nagy Nick Avatar answered Sep 24 '22 20:09

Nagy Nick