reCAPTCHA AJAX API 在 Safari 的模式对话框中无法一致工作

发布于 2024-08-19 07:12:01 字数 3803 浏览 7 评论 0 原文

我通过 AJAX API 使用 reCAPTCHA 在模式对话框中显示验证码。我使用 jqModal 来显示框,并且使用 AJAX 版本的 reCAPTCHA,因为 PHP 版本已经存在 jqModal 的错误(已知错误:http://markmail.org/message/bvip5vyb3czm7ngu)。

现在,reCAPTCHA 在 Firefox 中运行良好。但在 Safari 中,它并不总是显示。有时,它工作正常,但大约 20% 的时间,不会显示 reCAPTCHA 框。

jqModal 声明如下所示:

$().ready(function() {
  $('#modalBox_register').jqm({
  ajax: '/modals/register.php',
  trigger: 'a#registerButtonLink',
  onShow: function(h) {
   h.w.css('opacity', 1.00).fadeIn(300);
   },
  onHide: function(h) {
   h.w.fadeOut(300, function() { if (h.o) h.o.remove(); });
   }
 });
});

模式框中的 HTML/PHP 如下所示:

<div id="registerModal">
 <p class="caption">Registration form:</p>
 <form name="registerForm" id="modalRegisterForm" class="modalForm" action="/register/" method="post">

   <table cellspacing="15" border="0">
    <tr>
     <td class="left"><label for="firstName">First Name:</label></td>
     <td class="right"><input type="text" name="firstName" id="firstName" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="lastName">Last Name:</label></td>
     <td class="right"><input type="text" name="lastName" id="lastName" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="email">Email Address:</label></td>
     <td class="right"><input type="text" name="email" id="email" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="password">Password:</label></td>
     <td class="right"><input type="password" name="password" id="password" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="passwordConfirm">Confirm Your Password:</label></td>
     <td class="right"><input type="password" name="passwordConfirm" id="passwordConfirm" value="" class="registerModalTextField" /></td>
    </tr>

    <tr>
     <td class="left">&nbsp;</td>
     <td class="right"><div id="termswrap">
      <input id="terms" type="checkbox" name="terms" />
               <label id="lterms" for="terms">&nbsp;I have read and accept the <a href="/backmatter/termsofuse/">Terms of Use.</a><br /></label>
              </div><!-- /#termswrap --></td>
    </tr>


    <!-- reCAPTCHA -->
    <tr>
     <td class="left"><label for="captcha">Are you human?</label></td>
     <td class="right"><!-- Using the reCAPTCHA AJAX API, because the non-AJAX API is buggy with jqModal -->
     <div id="recaptcha_div"></div>
     <script type="text/javascript"
      src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script> <script
      type="text/javascript">
          Recaptcha.create("123456789...",
           "recaptcha_div", {
             theme: "white"
          });
         </script>

     </td>
    </tr>


    <tr>
     <td class="left">&nbsp;</td>
     <td class="right"><input type="image" id="submitButton" src="/images/modals/button_register.png" value="Submit" alt="Submit" name="submit" /></td>
    </tr>
   </table>


 </form>
</div><!--/#registerModal-->

有人知道为什么 reCAPTCHA AJAX 调用在 Safari 中无法正常工作吗?

I'm using reCAPTCHA via its AJAX API to display the captcha in a modal dialog box. I'm using jqModal to display the boxes, and I'm using the AJAX version of reCAPTCHA because the PHP version is already buggy with jqModal (a known bug: http://markmail.org/message/bvip5vyb3czm7ngu).

Now, the reCAPTCHA works fine in Firefox. But in Safari, it doesn't always get displayed. Sometimes, it works fine, but about 20% of the time, no reCAPTCHA box is displayed.

The jqModal declaration looks like this:

$().ready(function() {
  $('#modalBox_register').jqm({
  ajax: '/modals/register.php',
  trigger: 'a#registerButtonLink',
  onShow: function(h) {
   h.w.css('opacity', 1.00).fadeIn(300);
   },
  onHide: function(h) {
   h.w.fadeOut(300, function() { if (h.o) h.o.remove(); });
   }
 });
});

And the HTML/PHP within the modal box looks like this:

<div id="registerModal">
 <p class="caption">Registration form:</p>
 <form name="registerForm" id="modalRegisterForm" class="modalForm" action="/register/" method="post">

   <table cellspacing="15" border="0">
    <tr>
     <td class="left"><label for="firstName">First Name:</label></td>
     <td class="right"><input type="text" name="firstName" id="firstName" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="lastName">Last Name:</label></td>
     <td class="right"><input type="text" name="lastName" id="lastName" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="email">Email Address:</label></td>
     <td class="right"><input type="text" name="email" id="email" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="password">Password:</label></td>
     <td class="right"><input type="password" name="password" id="password" value="" class="registerModalTextField" /></td>
    </tr>
    <tr>
     <td class="left"><label for="passwordConfirm">Confirm Your Password:</label></td>
     <td class="right"><input type="password" name="passwordConfirm" id="passwordConfirm" value="" class="registerModalTextField" /></td>
    </tr>

    <tr>
     <td class="left"> </td>
     <td class="right"><div id="termswrap">
      <input id="terms" type="checkbox" name="terms" />
               <label id="lterms" for="terms"> I have read and accept the <a href="/backmatter/termsofuse/">Terms of Use.</a><br /></label>
              </div><!-- /#termswrap --></td>
    </tr>


    <!-- reCAPTCHA -->
    <tr>
     <td class="left"><label for="captcha">Are you human?</label></td>
     <td class="right"><!-- Using the reCAPTCHA AJAX API, because the non-AJAX API is buggy with jqModal -->
     <div id="recaptcha_div"></div>
     <script type="text/javascript"
      src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script> <script
      type="text/javascript">
          Recaptcha.create("123456789...",
           "recaptcha_div", {
             theme: "white"
          });
         </script>

     </td>
    </tr>


    <tr>
     <td class="left"> </td>
     <td class="right"><input type="image" id="submitButton" src="/images/modals/button_register.png" value="Submit" alt="Submit" name="submit" /></td>
    </tr>
   </table>


 </form>
</div><!--/#registerModal-->

Does anybody have a clue why the reCAPTCHA AJAX call isn't working properly in Safari?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森罗 2024-08-26 07:12:01

我认为 Safari 在重新渲染标签时会重新执行 javascript。当对话框打开时,模式对话框中的任何内容都会重新呈现。此外,我怀疑重新渲染后,recaptcha 使用的 document.write 会对其位置感到困惑并变得混乱。无论如何,这就是解决我的问题的方法:

$('#captcha-form script').remove();

'captcha-form' 是包含验证码的表单的 id。删除脚本标签,这样当 jQuery 移动脚本后 Safari 重新呈现脚本时,脚本就不会再次执行。脚本创建的事件处理程序不在脚本标记中,因此它们会保留下来。

I think that Safari re-executes javascript when it re-renders the tags. And anything in a modal dialog gets re-rendered when the dialog opens. Furthermore, I suspect that after having been re-rendered, the document.write used by recaptcha gets confused about where it is and messes up. In any case, here's what fixed my problems:

$('#captcha-form script').remove();

'captcha-form' is the id of the form containing the captcha. Remove the script tags so the scripts don't get executed a second time when Safari re-renders them after jQuery moves them. The event handlers created by the script aren't in the script tags, so they survive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文