2019, Chrome 76, approach to autocomplete off

后端 未结 9 2068
忘掉有多难
忘掉有多难 2020-12-29 04:43

There are are few posts out there about this. You spend hours going through each answer, testing, reading comments, to find that there is no solution. What have you done in

9条回答
  •  孤城傲影
    2020-12-29 05:16

    Chrome version 81.

    For me, when input type is TEL, EMAIL or SEARCH, it WORKS with autocomplete='disabled'. When input type is NUMBER, it WORKS with autocomplete='off'.

    But when input type is TEXT .. it may works with autocomplete='off'. If not, it will do with autocomplete='disabled'.

    You can try this, perhaps it will work for you (it works in 95% of cases for me) :

    // Désactivation de l'autocomplete des input text
    function setAutocomplete(val) {
        var E = document.getElementsByTagName('INPUT');
        for (var i = 0 ; i < E.length ; i++) {
            if (E[i].name == 'txt_nom') { console.log('txt_nom', E[i]); }
            var type = E[i].type.toUpperCase();
            if (E[i].autocomplete != '') { continue; }
            if (type == 'HIDDEN') {
                //
            } else if (type == 'NUMBER') {
                E[i].autocomplete = 'off';
            } else if ((type == 'TEL') || (type == 'EMAIL') || (type == 'SEARCH')) {
                E[i].autocomplete = 'disabled';
            } else {
                E[i].autocomplete = val;
            }
        }
    }
    
    // Exécution de diverses fonctions à la fin de chaque chargement
    window.addEventListener("load", function() {
        // Désactivation de l'autocomplete des input text
        setAutocomplete('off');
    });
    

提交回复
热议问题