' autocomplete= ' off ' does not work in chrome

Source: Internet
Author: User

Come on _linda.

' autocomplete= ' off ' does not work in chrome

We enter information in the form input box, after submitting the form, when we re-enter the form page, double-click the input box, the previous submission will appear, because the browser will generally record the input box before submitting the form information. This is what this article is about to AutoComplete.

AutoComplete control refers to the user in the text box to enter the first few letters or a man, the control can be stored in the text or database data from the beginning of all the data to the user, for the user to choose, to provide convenience.

The default value for the AutoComplete of the input box (Input,textarea, select) is on, meaning whether the browser automatically records the previously entered value.

Sometimes the user does not want to record the previously entered value, then it needs to close AutoComplete.

1. We can achieve the purpose of closing AutoComplete by adding it to the form form or by adding autocomplete= "off" to some of the input boxes individually.

1.1 Add autocomplete= "off" to the form form.

<form method= "POST" action= "login.php" name= "Login" autocomplete= "Off" >

</form>

1.2 Add autocomplete= "off" in the input box

<input id= "username" type= "text" name= "username" maxlength= "$" autocomplete= "off" >

2. One exception is the input[type= "password" in the form, and when you click Save Password, the user name and password input box is automatically populated in the Chrome browser, and IE and Firefox are different. In order to unify the browser style, we need to modify the chrome issue.

3-hour solution available

2.1 Modifying value values

(function () {
if (Navigator.userAgent.toLowerCase (). IndexOf ("chrome")! =-1) {
var selectors = document.getElementsByTagName ("input");
for (Var i=0;i<selectors.length;i++) {
if ((Selectors[i].type!== "Submit") && (selectors[i].type!== "password") {
Selectors[i].value = "";
}
}
SetTimeout (function () {
for (Var i=0;i<selectors.length;i++) {
if (Selectors[i].type!== "Submit") {
Selectors[i].value = "";
}
}
},100)
}
})()

2.2 Modifying the Disabled property

(function () {
if (Navigator.userAgent.toLowerCase (). IndexOf ("chrome")! =-1) {
var selectors = document.getElementsByTagName ("input");
for (Var i=0;i<selectors.length;i++) {
if ((Selectors[i].type!== "Submit") && (selectors[i].type!== "password") {
selectors[i].disabled= true;
}
}
SetTimeout (function () {
for (Var i=0;i<selectors.length;i++) {
if (Selectors[i].type!== "Submit") {
Selectors[i].disabled= false;
}
}
},100)
}
})()

2.3 Removes "name" and "id" attributes

(function () {
if (Navigator.userAgent.toLowerCase (). IndexOf ("chrome")! =-1) {
var selectors = document.getElementsByTagName ("input");
for (Var i=0;i<selectors.length;i++) {
if ((Selectors[i].type!== "Submit") && (selectors[i].type!== "password") {
var input = selectors[i];
var inputname = Selectors[i].name;
var inputid = selectors[i].id;

Selectors[i].removeattribute ("name");
Selectors[i].removeattribute ("id");
SetTimeout (function () {
Input.setattribute ("name", InputName);
Input.setattribute ("id", inputID);
},1)
}

}

}
})()

Personal comparison recommends a third method, by removing the name and ID of input to achieve the effect

' autocomplete= ' off ' does not work in chrome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.