Google Recaptcha 不在 fancybox ajax 弹出窗口上工作



Google Recaptcha 不在 fancybox ajax 生成的表单上工作。

终于找到了解决方案。波纹管代码对我来说工作正常。

  1. 包括 Google Recaptcha api js

    <script src="https://www.google.com/recaptcha/api.js"></script>
    
  2. 添加元素 HTML

     <div class="g-recaptcha" id="recaptcha" ></div>
    
  3. 添加脚本

    <script type="text/javascript">
      $(document).ready(function() {
        $("[element_id_or_class]").fancybox({
           padding     : 0,
           maxWidth : 800,
           maxHeight    : 600,
           fitToView    : false,
           width        : 'auto',
           height       : 'auto',
           autoSize : true,
           openEffect   : 'none',
           closeEffect  : 'none',           
           ajax: {
             complete: function(jqXHR, textStatus) {
                grecaptcha.render('recaptcha', {
                    sitekey: [RECAPTCHA_SITE_KEY],
                    callback: function(response) {
                        console.log(response);
                    }           
                });
            }
          }
        });
     });
     </script>
    

最新更新