Rendering reCAPTCHA v2.0 widget within Backbone view

ぃ、小莉子 提交于 2019-12-04 19:11:52

I figured out the solution, by pulling in the recaptcha script directly from the view which renders it. Hope this helps someone in the future.

loadCaptcha: function() {
    var self = this;
    var getRecaptchaResponse = function(response) {
      self.captchaResponse = response;
    };

    var renderCaptcha = function() {
      self.captchaWidgetId = grecaptcha.render('recaptcha-container-' + self.model.get('Id'), {
          sitekey : service.settings.recaptchaSiteKey,
          callback: getRecaptchaResponse
      });
    };

    window.renderCaptcha = renderCaptcha;

    $.getScript('https://www.google.com/recaptcha/api.js?onload=renderCaptcha&render=explicit', function() {});
},

I would put your captch script in a backbone view. Then put it in the render of your main view. Like that it's modular you have a main view and a subview containing the captcha which is loaded when the main view is rendered.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!