[ACCEPTED]-Disable Firefox's Auto-fill-firefox

Accepted answer
Score: 11

Putting two dummy fields in between the 9 actual username field and the actual password 8 field worked for me, e.g.:

<input name = "Username" type="text" autocomplete="off">
<input name = "DummyUsername" type="text" style="display:none;">
<input name = "DummyPassword" type="password" style="display:none;">
<input name = "Password" type="password" autocomplete="new-password">

This prevented 7 the autofill of the username, as well as 6 the autofill of the password.

autocomplete="new-password" is 5 apparently not fully implemented, but can 4 help with some browsers. I doubt that it 3 was helpful with FireFox, but it is there 2 for future versions in case the feature 1 is more widely adopted.

Score: 10

If the problem is that FF is populating 10 the fields when the user refreshes, this 9 is actually a feature of Firefox to try 8 to help the user in the case of accidental 7 refresh so they don't lose whatever they 6 have typed. I don't think you can override 5 this with the HTML. You could use JavaScript 4 to clear/reset all the relevant form values 3 on page load. If a form.reset() on the form 2 doesn't work, you will have to iterate over 1 the form elements and clear them like this:

for (i = 0; i < frm_elements.length; i++)
{
    field_type = frm_elements[i].type.toLowerCase();
    switch (field_type)
    {
    case "text":
    case "password":
    case "textarea":
    case "hidden":
        frm_elements[i].value = "";
        break;
    case "radio":
    case "checkbox":
        if (frm_elements[i].checked)
        {
            frm_elements[i].checked = false;
        }
        break;
    case "select-one":
    case "select-multi":
        frm_elements[i].selectedIndex = -1;
        break;
    default:
        break;
    }
}
Score: 3

Firefox only honors autocomplete="off" on the form, not individual 5 elements (unlike IE).

Another option is to 4 change the field names to strange things 3 like name="_u_sern_ame" to confuse any field recognition systems 2 if you want to disable the autofill of someones 1 details.

Score: 3

I've had a similar issue for the password 5 field in a form on the page.

If there is 4 an input tag with type = password in a form 3 tag on the page Firefox is just automatically 2 populating the password:

<form>
    <input type='password' />
</form>

Here's the code 1 I used to fix this specific issue:

$('input[type=password]').val('')
Score: 2

I had this problem myself. Mike's answer 7 is close, but not perfect in my opinion: it 6 empties elements, even if a value attribute may 5 want to set it.

On pageload, I do the following. It 4 uses only a little jQuery.

// Reset input elements to their HTML attributes (value, checked)
$("input").each(function(){
    // match checkbox and radiobox checked state with the attribute
    if((this.getAttribute('checked')==null) == this.checked)
        this.checked = !this.checked;
    // reset value for anything else
    else this.value = this.getAttribute('value')||'';
});

// Select the option that is set by the HTML attribute (selected)
$("select").each(function(){
    var opts = $("option",this), selected = 0;
    for(var i=0; i<opts.length; i++) 
        if(opts[i].getAttribute('selected')!==null) 
            selected = i;

    this.selectedIndex = selected||0;
}); 


No jQuery?

Use 3 document.getElementsByTagName to select the inputs and selects, then iterate over 2 them and replace this by the iterated element.
Select 1 the options with .getElementsByTagName('option').

Score: 2

autocomplete='off' will not prevent whether in input or form put 1 a

<input type='password' style='display: none;' />

before your real password input.

Score: 2

what worked for me is

autocomplete="new-password"

0

Score: 2

In some cases, the browser will keep suggesting 6 autocompletion values even if the autocomplete 5 attribute is set to off. This unexpected 4 behavior can be quite puzzling for developers. The 3 trick to really forcing the no-autocompletion 2 is to assign a random string to the attribute, for 1 example:

autocomplete="nope"

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

Tried in major browsers and it works!

Score: 1

This post suggest to use (other) dummy fields 3 which will be autofilled, you can hide those 2 with css. But this would probably work better 1 with password fields than others.

Score: 1

This actually works with a password field 1 in FireFox:

$(window).load(function(){
    $('#pass').val('');
});
Score: 0

If it is indeed a Firefox bug, you could 3 use an onSubmit event to clear out the hidden 2 fields. In the form code:

<form onSubmit="clearFieldsIfPopulated(this)">
  <input type="hidden" name="field1"> <input type="submit">
</form>

Example Javascript 1 function:

function clearFieldsIfPopulated(form) {
  if (form.field1.value != "") {
    form.field1.value == "";
  }
}

More Related questions