Is it possible to disable Firefox\'s auto-fill feature without disabling auto-complete?
I know I can do this:
autocomplete=\"off\"
<
I had this problem myself. Mike's answer is close, but not perfect in my opinion: it empties elements, even if a value
attribute may want to set it.
On pageload, I do the following. It 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 document.getElementsByTagName
to select the input
s and select
s, then iterate over them and replace this
by the iterated element.
Select the options with .getElementsByTagName('option')
.
I've had a similar issue for the password field in a form on the page.
If there is an input tag with type = password in a form tag on the page Firefox is just automatically populating the password:
<form>
<input type='password' />
</form>
Here's the code I used to fix this specific issue:
$('input[type=password]').val('')
Putting two dummy fields in between the actual username field and the actual password 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 the autofill of the username, as well as the autofill of the password.
autocomplete="new-password" is apparently not fully implemented, but can help with some browsers. I doubt that it was helpful with FireFox, but it is there for future versions in case the feature is more widely adopted.
Firefox only honors autocomplete="off"
on the form, not individual elements (unlike IE).
Another option is to change the field names to strange things like name="_u_sern_ame"
to confuse any field recognition systems if you want to disable the autofill of someones details.
what worked for me is
autocomplete="new-password"
This actually works with a password field in FireFox:
$(window).load(function(){
$('#pass').val('');
});