C
C
Cyril2017-11-10 23:32:02
JavaScript
Cyril, 2017-11-10 23:32:02

How to download js from another site on click?

Hello! Is it possible to make google recaptcha load on click of a button?
Same as inserting into html:

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

If it were possible to copy js there, otherwise it is constantly changing ... if only it could be parsed and executed on click ... in any case, if parsing, then you need to take into account
window['___grecaptcha_cfg']['render'] = 'explicit'
window['___grecaptcha_cfg']['onload'] = 'reCaptchaCallback'
I have 2 captchas on my site, at best +2 seconds to load the site...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-11-11
@draaax

$('#MYBTN').on('click',function(){
    var captchaContainer = null;
    var loadCaptcha = function() {
      captchaContainer = grecaptcha.render('captcha_container', {
        'sitekey' : 'Your sitekey',
        'callback' : function(response) {
          console.log(response);
        }
      });
    };
    loadCaptcha();
 });

<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
      <div id="captcha_container"></div>
      <input type="button" id="MYBTN" value="MYBTN">
      <script src="https://www.google.com/recaptcha/api.js?onload=loadCaptcha&render=explicit"></script>

© https://stackoverflow.com/a/35245851

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question