Chrome ignores autocomplete=“off”

后端 未结 30 1506
礼貌的吻别
礼貌的吻别 2020-11-22 00:42

I\'ve created a web application which uses a tagbox drop down. This works great in all browsers except Chrome browser (Version 21.0.1180.89).

Despite both the

30条回答
  •  被撕碎了的回忆
    2020-11-22 01:04

    Prevent autocomplete of username (or email) and password:

    
    
    

    Prevent autocomplete a field (might not work):

    
    

    Explanation:

    autocomplete still works on an despite having autocomplete="off", but you can change off to a random string, like nope.


    Others "solutions" for disabling the autocomplete of a field (it's not the right way to do it, but it works):

    1.

    HTML:

    
    

    JS (onload):

    (function() {
        var some_id = document.getElementById('some_id');
        some_id.type = 'text';
        some_id.removeAttribute('autocomplete');
    })();
    

    or using jQuery:

    $(document).ready(function() {
        var some_id = $('#some_id');
        some_id.prop('type', 'text');
        some_id.removeAttr('autocomplete');
    });
    

    2.

    HTML:

    JS (onload):

    (function() {
        var input = document.createElement('INPUT');
        input.type = 'text';
        document.getElementById('form').appendChild(input);
    })();
    

    or using jQuery:

    $(document).ready(function() {
        $('', {
            type: 'text'
        }).appendTo($('#form'));
    });
    

    To add more than one field using jQuery:

    function addField(label) {
      var div = $('
    '); var input = $('', { type: 'text' }); if(label) { var label = $('
    
    


    Works in:

    • Chrome: 49+

    • Firefox: 44+

提交回复
热议问题