ReCAPTCHA ajax加载主题问题

发布于 2024-10-21 16:55:10 字数 1313 浏览 3 评论 0原文

无法弄清楚如何主题化 ajax 加载的验证码。下面的代码不起作用。
来自 Google Recaptcha

看到了这篇文章< a href="https://stackoverflow.com/questions/2458187/recaptcha-ajax-api-custom-theme-not-working">Recaptcha ajax API 自定义主题不起作用,但我肯定是在本地主机中查看验证码工作正常,只是不改变主题。

有人对如何让白色主题工作有建议吗?

    <script type='text/javascript'>
        var RecaptchaOptions = {
            theme : 'white'
         };
    </script>
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" 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>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content");
        });

    });
    </script>

Can not figure out how to theme an ajax loaded recaptcha. The below code does not work.
From Google Recaptcha

Saw this post Recaptcha ajax API custom theme not working, but I am definitely viewing in localhost and recaptcha is working fine, just not changing themes.

Anyone have advice on how to get the white theme to work?

    <script type='text/javascript'>
        var RecaptchaOptions = {
            theme : 'white'
         };
    </script>
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" 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>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content");
        });

    });
    </script>

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

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

发布评论

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

评论(4

喜爱纠缠 2024-10-28 16:55:10

@jhanifen:在使用 http://wiki.recaptcha.net/index.php/ 中的大部分代码后,我得到了它的工作安装,试试这个——

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    </head>

    <body>

    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {
                Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", 
                "recaptcha_content",
                {
                    theme: "white", 
                    callback: Recaptcha.focus_response_field
                }
            );
        });
    });
    </script>

    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" 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>
    </div>

    </body>
</html>

@jhanifen: I got it working after using most of the code from http://wiki.recaptcha.net/index.php/Installation, try this --

<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    </head>

    <body>

    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {
                Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", 
                "recaptcha_content",
                {
                    theme: "white", 
                    callback: Recaptcha.focus_response_field
                }
            );
        });
    });
    </script>

    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" 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>
    </div>

    </body>
</html>
最冷一天 2024-10-28 16:55:10

我看起来不像您要添加已设置的选项 RecapthcaOptions。尝试更改为:

$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
        function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content", RecaptchaOptions);
});

查看文档,传递给的第三个选项.create() 方法是选项。您在函数外部设置一个变量来设置选项,但不包含它们。

I't doesn't look like you are adding your options that you have set RecapthcaOptions. Try changing to:

$.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
        function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content", RecaptchaOptions);
});

See the doc's, the third option passed to the .create() method is the options. You are setting up a variable outside the function to set the options, but don't include them.

旧街凉风 2024-10-28 16:55:10

首先,您的密钥无效或错误,或者您希望将其发布在这里:D
如果不想要的话。尝试获取一个新的,也许将其设为全局的(可能会影响本地主机的东西)。或者在您指定的域上上传并测试代码。

该片段适用于我的全局公钥,我直接在创建时设置主题

<html>
<head>
<title>recaptcha test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<body>    
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=publickey" 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>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        Recaptcha.create("publickey",
                         "recaptcha_content", {
                             theme: "white",
                             callback: Recaptcha.focus_response_field
        });
    });
    </script>   
</body>
</html>

First of all, your key is invalid or wrong, or you wanted that to be posting here :D
If not wanted. try to get a new one, and maybe make it a global one (could affect the localhost stuff). Or upload and test the code on the domain you specified.

This snippet works for my global public key, i set the theme directly on creation

<html>
<head>
<title>recaptcha test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
</head>
<body>    
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=publickey" 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>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        Recaptcha.create("publickey",
                         "recaptcha_content", {
                             theme: "white",
                             callback: Recaptcha.focus_response_field
        });
    });
    </script>   
</body>
</html>
时间你老了 2024-10-28 16:55:10

按照奥卡姆剃刀的方式,您可以验证设置主题的脚本是否位于表单元素之前。正如文档中多次所述,该脚本在表单元素内部或之后不起作用。

Going the Occam's Razor way, can you verify that the script for setting the theme is before the form element. As stated several times in the docs, the script does not work inside or after the form element.

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