如何隐藏启用JavaScript的浏览器的recaptcha并通过html验证 [英] How to hide recaptcha for JavaScript enabled browsers and pass html validation

查看:1282
本文介绍了如何隐藏启用JavaScript的浏览器的recaptcha并通过html验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望仅对非启用JavaScript的浏览器使用recaptcha。为此,我尝试使用< noscript> 标记,如下所示。

 <!DOCTYPE html> 
< html>
< head>
< title> recaptcha< / title>
< / head>

< body>
< noscript>
<?php
require_once('recaptcha-php-1.11 / recaptchalib.php');
echo recaptcha_get_html('xxx');
?>
< / noscript>
< p>完成< / p>
< / body>
< / html>

使用 http://validator.w3.org ,我收到以下错误:

 错误第11行,第11列:元素noscript不能出现为noscript元素的后代。 

< noscript>

错误第12行,第147列:iframe元素上的frameborder属性已过时。改用CSS。

... WAABIZRfA-fKq8eVkFjK_Fheight =300width =500frameborder =0>< / iframe>< br />
解决方案

reCAPTCHA PHP库将在您的DOM内部渲染更多< noscript>标签现有的,导致无效的HTML - 因为默认情况下它使用javascript。



请看这里 - 显示无插件的reCAPTCHA - 特别是显示无插件的reCAPTCHA部分,它向您展示了HTML标记需要的样子。在noscript标签中粘贴代码...

 < iframe src =http://www.google.com /验证码/ API /无脚本?K = your_public _key
height =300width =500frameborder =0>< / iframe>< br>
< textarea name =recaptcha_challenge_fieldrows =3cols =40>
< / textarea>
< input type =hiddenname =recaptcha_response_field
value =manual_challenge>


I wish to use recaptcha for only non-JavaScript enabled browsers. To do so, I tried using the <noscript> tag as shown below.

<!DOCTYPE html>
<html>
    <head>
        <title>recaptcha</title>
    </head>

    <body>
        <noscript>
            <?php
                require_once('recaptcha-php-1.11/recaptchalib.php');
                echo recaptcha_get_html('xxx');
            ?>
        </noscript>
        <p>Done</p>
    </body>
</html>

When validating the code using http://validator.w3.org, I received the following errors:

Error Line 11, Column 11: The element noscript must not appear as a descendant of the noscript element.

    <noscript>

Error Line 12, Column 147: The frameborder attribute on the iframe element is obsolete. Use CSS instead.

…WAABIZRfA-fKq8eVkFjK_F" height="300" width="500" frameborder="0"></iframe><br/>

Is there anything I can do to remove these errors (at least the first one)? Also, am I better off detecting JavaScript use serverside and just not echoing the captcha?

解决方案

The reCAPTCHA PHP library will be rendering a further < noscript> tag into the DOM inside of your existing one, causing the invalid HTML - because by default it uses javascript.

Take a look here - Displaying reCAPTCHA Without Plugins - Specifically the section "Displaying reCAPTCHA Without Plugins". It shows you an example of what the HTML markup needs to look like. You could try just pasting in the code in the noscript tags...

<iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
     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">

这篇关于如何隐藏启用JavaScript的浏览器的recaptcha并通过html验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆