How to disable autocomplete for all major browsers
How to disable autocomplete in major browsers for a specific input and / or full form.
I found this solution:
<input type="text" name="foo" autocomplete="off" />
However, this doesn't seem to work in all browsers. For example, I had problems with firefox.
Edit:
My firefox issue was resolved. This leaves the following: can I turn off the autocomplete of the form or do I need to give each input autocomplete = "off"
source to share
Autocomplete
should work with the following types <input>
: text, search, url, tel, email, password, datepickers, range and color.
But alas, you can try adding autocomplete='off'
to the tag <form>
instead of the tag <input>
, unless something prevents you from doing it.
If that doesn't work, you can also use JavaScript:
if (document.getElementsByTagName) {
var inputElements = document.getElementsByTagName("input");
for (i=0; inputElements[i]; i++) {
if (inputElements[i].className && (inputElements[i].className.indexOf("disableAutoComplete") != -1)) {
inputElements[i].setAttribute("autocomplete","off");
}
}
}
Or in jQuery:
$(document).ready(function(){
$(':input').live('focus',function(){
$(this).attr('autocomplete', 'off');
});
});
source to share
You can try manually clearing the text boxes on page load with javascript, like this:
window.onload = function() {
elements = document.getElementsByTagName("input");
for (var i=0; i<elements.length; ++i) {
elements[i].value = "";
}
};
This may not work if done before autocomplete. Another option is to name
randomly generate some of the attributes for your inputs every time the page is rendered (and cut them out when the server processes the submission), then the browser won't try to autocomplete.
See also Autocomplete = "off" compatible with all modern browsers?
source to share