我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
浏览器不关心自动完成=关闭自动,甚至填充凭据到错误的文本字段?
我通过将密码字段设置为只读并激活它来修复它,当用户单击进入它或使用tab键到该字段时。
修复浏览器自动填充:只读和设置可写的焦点(在鼠标点击和标签通过字段)
<input type="password" readonly
onfocus="$(this).removeAttr('readonly');"/>
更新: Mobile Safari在字段中设置光标,但不显示虚拟键盘。新的修复工作像以前一样,但处理虚拟键盘:
<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) {
this.removeAttribute('readonly');
// fix for mobile safari to show virtual keyboard
this.blur(); this.focus(); }" />
现场演示https://jsfiddle.net/danielsuess/n0scguv6/
/ / UpdateEnd
顺便说一下,更多关于我观察到的信息:
Sometimes I notice this strange behavior on Chrome and Safari, when there are password fields in the same form. I guess, the browser looks for a password field to insert your saved credentials. Then it autofills username into the nearest textlike-input field , that appears prior the password field in DOM (just guessing due to observation). As the browser is the last instance and you can not control it, sometimes even autocomplete=off would not prevent to fill in credentials into wrong fields, but not user or nickname field.
其他回答
自动完成=“关闭”不再工作。
尝试使用一个随机字符串来代替"Off",例如Autocomplete="NoAutocomplete"
我希望这能有所帮助。
除了给它一个自动补全的假字段外,所有的解决方案都不起作用。我做了一个React组件来解决这个问题。
import React from 'react'
// Google Chrome stubbornly refuses to respect the autocomplete="off" HTML attribute so
// we have to give it a "fake" field for it to autocomplete that never gets "used".
const DontBeEvil = () => (
<div style={{ display: 'none' }}>
<input type="text" name="username" />
<input type="password" name="password" />
</div>
)
export default DontBeEvil
我刚刚尝试了下面的方法,它似乎在Chrome 53上起了作用——当输入密码字段时,它还禁用了“使用密码用于:”下拉菜单。
简单地设置你的密码输入类型为文本,然后添加onfocus处理程序(内联或通过jQuery/vanilla JS)来设置类型为密码:
onfocus="this.setAttribute('type','password')"
或者更好:
onfocus="if(this.getAttribute('type')==='text') this.setAttribute('type','password')"
Autocomplete =off在现代浏览器中基本上被忽略了——主要是由于密码管理器等。
你可以尝试添加这个autocomplete="new-password",它不是所有浏览器都完全支持,但在一些浏览器上是有效的
将输入类型属性更改为type="search"。
谷歌不会对输入的搜索类型应用自动填充。