I have a few text boxes on my page and find it very annoying the auto complete functionality. Is there any 开发者_如何学JAVAway to remove this from my site?
Auto Complete
As of HTML 5, the auto complete is a form / input Attribute suported by all major browsers.
<form name="form1" id="form1" method="post" autocomplete="off" action="#">
Also, see here some more information about its usage:
- W3C cheatsheet
- MDN
- MSDN
Auto Capitalize and Auto Correct
If you are preparing an web application or any other Smartphone friendly web page, you might be interested in knowing how to: Disable Autocomplete, Autocapitalize, and Autocorrect.
<input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
<textarea autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
Add autocomplete="off"
as form attribute and it applies to all fields inside the form.
Example : <form action="#" autocomplete="off">
This is how you can do this
autocomplete="new-text"
Add inside you input box or textarea
autocomplete="off" can be added as a non-standard attribute to input fields. not sure which browsers besides IE support it though.
autocomplete="off" do not support instead of that use this 'autocomplete="new-password"'
You can use jQuery to add the autocomplete attribute after the page loads. That's the best way I found to force Chrome to listen.
<script type="text/javascript" language="javascript">
jQuery(function() {
jQuery('#my_input').attr('autocomplete', 'off');
});
</script>
<input type="text" name="my_input" id="my_input">
autocomplete="off"
works in Firefox, but it doesn't work in Chromium browsers on Ubuntu, so you need to check if the browser is a Chromium browser, and if it is use autocomplete="disabled"
, otherwise use autocomplete="off"
.
var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );
$("#mobile").prop("autocomplete", is_chrome ? 'disabled' : 'off');
Simplest way:
Remove name
attribute, and add always a different string in autocomplete
.
$(document).ready(function () {
setTimeout(function () {
var randomicAtomic = Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10);
$('input[type=text]').removeAttr('name');
$('input[type=text]').attr('autocomplete', randomicAtomic);
}, 1000);
})
use autocomplete = "off" in Html.BeginForm
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @id = "myForm", @autocomplete = "off" }))
{
@Html.EditorFor(model => model.field, new { htmlAttributes = new { @class = "text-box form-control" } })
<input type="submit" value="Save" />
}
精彩评论