Disable Chrome form autocomplete

Google Chrome ignores the autocomplete="off" or automcomplete="false" in forms.

At the time of the writing the following did the trick. You set the input field to a readonly state and remove the attribute after loading the page.

var timeoutID;
timeoutID = window.setTimeout(function() {
    $('.my-form input[readonly=""]').on('focus', function(){
        $(this).removeAttr('readonly');
    });
}, 300);

Why a timeout?

If you try to remove the readonly on document ready it will not work on Chrome. Also, if you use the on focus event, the iPad keyboard will not show up.

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*