Is there a W3C valid way to disable autocomplete in a HTML form?

后端 未结 18 1035
心在旅途
心在旅途 2020-11-22 05:58

When using the xhtml1-transitional.dtd doctype, collecting a credit card number with the following HTML



        
相关标签:
18条回答
  • 2020-11-22 06:12

    Another way - which will also help with security is to call the input box something different every time you display it: just like a captha. That way, the session can read the one-time only input and Auto-Complete has nothing to go on.

    Just a point regarding rmeador's question of whether you should be interfering with the browser experience: We develop Contact Management & CRM systems, and when you are typing other people's data into a form you don't want it constantly suggesting your own details.

    This works for our needs, but then we have the luxury of telling users to get a decent browser:)

    autocomplete='off' 
    
    0 讨论(0)
  • 2020-11-22 06:15

    No, a good article is here in Mozila Wiki.

    I would continue to use the invalid attribute. I think this is where pragmatism should win over validating.

    0 讨论(0)
  • 2020-11-22 06:15

    I suggest catching all 4 types of input:

    $('form,input,select,textarea').attr("autocomplete", "off");
    

    Reference:

    • http://www.w3.org/Submission/web-forms2/#the-autocomplete
    • http://dev.w3.org/html5/markup/input.html
    0 讨论(0)
  • 2020-11-22 06:15

    If you use jQuery, you can do something like that :

    $(document).ready(function(){$("input.autocompleteOff").attr("autocomplete","off");});
    

    and use the autocompleteOff class where you want :

    <input type="text" name="fieldName" id="fieldId" class="firstCSSClass otherCSSClass autocompleteOff" />
    

    If you want ALL your input to be autocomplete=off, you can simply use that :

    $(document).ready(function(){$("input").attr("autocomplete","off");});
    
    0 讨论(0)
  • 2020-11-22 06:15

    Note that there's some confusion about location of the autocomplete attribute. It can be applied either to the whole FORM tag or to individual INPUT tags, and this wasn't really standardized before HTML5 (that explicitly allows both locations). Older docs most notably this Mozilla article only mentions FORM tag. At the same time some security scanners will only look for autocomplete in INPUT tag and complain if it's missing (even if it is in the parent FORM). A more detailed analysis of this mess is posted here: Confusion over AUTOCOMPLETE=OFF attributes in HTML forms.

    0 讨论(0)
  • 2020-11-22 06:18

    I think there's a simpler way. Create a hidden input with a random name (via javascript) and set the username to that. Repeat with the password. This way your backend script knows exactly what the appropriate field name is, while keeping autocomplete in the dark.

    I'm probably wrong, but it's just an idea.

    0 讨论(0)
提交回复
热议问题