如何仅在 jQuery 对话框加载时加载 recaptcha 代码

发布于 2024-10-12 02:12:41 字数 1964 浏览 4 评论 0原文

我在 jQuery 对话框中有一个验证码。

由于某种原因,当我在 Firefox 中加载页面时,它会挂起(尽管在 IE/Chrome 上效果很好)。 我发现对话框中的验证码导致了它。

我认为,如果我仅在用户打开对话框时加载验证码,则可能会解决问题,并且还可以帮助我减少一般出站连接的数量。

这是与验证码相关的位的“查看源代码”:

<div id="dialog-form" title="Create new user"> 
    <p class="validateTips">You can also Connect with Facebook</p> 
    <fb:login-button perms="publish_stream,create_event,rsvp_event,user_birthday,user_events,user_hometown,user_location,user_online_presence">Login to Facebook</fb:login-button> 
    <form id="regform" action="" method="post"> 
    <fieldset> 
        <label for="name">Username</label> 
        <input type="text" name="username" id="name" class="text ui-widget-content ui-corner-all" value="" /> 
        <label for="email">Email</label> 
        <input type="text" name="email" id="email" class="text ui-widget-content ui-corner-all" value="" /> 
        <label for="password" style="float:left;">Password&nbsp;&nbsp;&nbsp;&nbsp;</label> 
        <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" /> 
        <input type="hidden" name="reg" value="reg" /> 
    </fieldset> 
    <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LerjL4SAAAAAG3sq_40sHyvch501El5JoNkHqOR"></script> 

    <noscript> 
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LerjL4SAAAAAG3sq_40sHyvch501El5JoNkHqOR" height="300" width="500" frameborder="0"></iframe><br/>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    </noscript>     </form> 
</div> 

它放置在页面底部,标签之前,因此它不是嵌套的或任何东西。

我该怎么做呢?

谢谢,

I have a recaptcha code within a jQuery dialog.

For some reason, when I load the page in firefox, it hangs (works great on IE/Chrome though).
I found that the recaptcha in the dialog is causing it.

I thought that if I would load the recaptcha code only when a user opens the dialog that might solve the issue and also help me reduce the amount of outbound connections in general.

this is the 'view source' of the bit that is related to the recaptcha:

<div id="dialog-form" title="Create new user"> 
    <p class="validateTips">You can also Connect with Facebook</p> 
    <fb:login-button perms="publish_stream,create_event,rsvp_event,user_birthday,user_events,user_hometown,user_location,user_online_presence">Login to Facebook</fb:login-button> 
    <form id="regform" action="" method="post"> 
    <fieldset> 
        <label for="name">Username</label> 
        <input type="text" name="username" id="name" class="text ui-widget-content ui-corner-all" value="" /> 
        <label for="email">Email</label> 
        <input type="text" name="email" id="email" class="text ui-widget-content ui-corner-all" value="" /> 
        <label for="password" style="float:left;">Password    </label> 
        <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" /> 
        <input type="hidden" name="reg" value="reg" /> 
    </fieldset> 
    <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LerjL4SAAAAAG3sq_40sHyvch501El5JoNkHqOR"></script> 

    <noscript> 
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LerjL4SAAAAAG3sq_40sHyvch501El5JoNkHqOR" height="300" width="500" frameborder="0"></iframe><br/>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    </noscript>     </form> 
</div> 

it's placed at the bottom of the page, right before the tag, so it's not nested or anything.

How can I do it?

Thanks,

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

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

发布评论

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

评论(4

避讳 2024-10-19 02:12:41

如果您计划在弹出对话框中使用 reCaptcha,我强烈建议使用 javascript api< /a>.我发现 FireFox 在这种情况下处理 iframe 时可能会遇到问题。

当您收到在客户端 JavaScript 中打开对话框的调用后,您可以像这样调用创建验证码:

Recaptcha.create(YOUR_API_KEY,
    "captcha_contain",
    {
    theme: "red",
    callback: Recaptcha.focus_response_field
    }
);

其中“captcha_contain”是对话框中元素的 id,可能是一个打开的 div。
它也会稍微改变您的服务器端代码,但您可以在 API 中阅读所有相关内容。

If you plan on using reCaptcha in a popup-dialog, I would strongly suggest using the javascript api. I've found that FireFox can have trouble handling the iframe in such situations.

After you receive a call to open the dialog in the client-side javascript, you call for the creation of the captcha like this:

Recaptcha.create(YOUR_API_KEY,
    "captcha_contain",
    {
    theme: "red",
    callback: Recaptcha.focus_response_field
    }
);

Where "captcha_contain" is the id of an element in your dialog, presumably an open div.
It will change your server-side code somewhat too, but you can read all about that in the API.

余厌 2024-10-19 02:12:41

此帖子表明这可能是由于 HTML 无效造成的。
在这种情况下,这是因为

被放置在 内部。
也许这也是你的情况?

无论如何,如果您确实想在对话框打开时加载验证码,则必须通过 AJAX 获取内容。
使用 jQuery UI 对话框中的 open 事件来决定何时检索验证码。
我不熟悉 reCaptcha 的 API,但也许有一个 Javascript API,否则您将不得不让 PHP 代码在单独的页面上为您呈现验证码(或以某种方式将其暴露给客户端)。

This thread suggests that it might be due to invalid HTML.
In that case it was because a <form> was placed inside of a <table>.
Might that be your case as well?

Anyhow, if you really want to load the captcha just on dialog open you will have to get the content through AJAX.
Use the open event in jQuery UI Dialog to decide when to retrieve your captcha.
I'm not familiar with the API of reCaptcha, but maybe there is an Javascript API, otherwise you will have to let your PHP code render that captcha for you on a separate page (or in some way expose it to the client).

往日 2024-10-19 02:12:41

我在使用 reCAPTCHA 和 Firefox 3.6 时遇到了类似的问题。顺便说一句,相同的代码在 IE 和 Chrome 上运行得很好。经过多次调试(以及上面答案中的一些提示),我发现表单中的

标记导致 jquery 崩溃。

只需删除

错误就消失了。

希望它能帮助其他人。

I was having a similar problem with reCAPTCHA and Firefox 3.6. On a side note, the same code worked great with IE and Chrome. After much debugging (and some tips from the answers above) I found that the <fieldset> tag inside my form was causing jquery to crash.

Simply removing the <fieldset> and the error went away.

Hope it helps others out there.

不知在何时 2024-10-19 02:12:41

我在 FF3.6 中使用灯箱时再次遇到这个问题 - 将 reCatpcha div 加载到页面中,但将其隐藏,直到表单的 onSubmit。

通过在 reCaptcha 表单上使用“可见性:隐藏”而不是“显示:无”解决了该问题。

(简单的修复,但当时很痛苦——以防万一它对其他人有用:))

I was getting this issue, again just in FF3.6 when using a lightbox — loading the reCatpcha div into the page but hiding it until onSubmit of the form.

Resolved the issue by using 'visibility: hidden' on the reCaptcha form rather than 'display: none'.

(Simple fix, but a pain at the time — just in case it's of use to anyone else :) )

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