我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
我创建了一个使用标签框下拉的web应用程序。除了Chrome浏览器(Version 21.0.1180.89),这在所有浏览器中都很有效。
尽管输入字段和表单字段都有autocomplete="off"属性,Chrome坚持显示该字段以前条目的下拉历史,这是删除标签框列表。
当前回答
直到上周,以下两种解决方案似乎都适用于Chrome、IE和Firefox。但随着Chrome 48版的发布(仍然是49版),它们不再适用:
表格顶部有以下内容:
<input style="display:none" type="text" name="fakeUsername"/>
<input style="display:none" type="password" name="fakePassword"/>
在密码输入元素中: 自动完成=“关闭”
因此,为了快速解决这个问题,我首先尝试使用一个主要的hack,即最初将密码输入元素设置为禁用,然后在document ready函数中使用setTimeout再次启用它。
setTimeout(function(){$('#PasswordData').prop('disabled', false);}, 50);
但这似乎太疯狂了,我做了更多的搜索,在禁用Chrome自动填充中找到了@tibalts的答案。他的答案是在密码输入中使用autocomplete="new-password",这似乎在所有浏览器上都可以工作(在这个阶段,我保留了上面的修复程序1)。
下面是谷歌Chrome开发者讨论中的链接: https://code.google.com/p/chromium/issues/detail?id=370363#c7
其他回答
除了给它一个自动补全的假字段外,所有的解决方案都不起作用。我做了一个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
更新:08/2022
我设法让自动补全通过包含得到尊重
autocomplete="new-password"
在每个单独的输入元素上。
E.g.
<input id="email" type="email" autocomplete="new-password"/>
我发布这个答案是为了给这个问题带来一个更新的解决方案。 我目前使用的是Chrome 49,没有给出的答案。 我也在寻找一个解决方案与其他浏览器和以前的版本。
把这些代码放在表单的开头
<div style="display: none;">
<input type="text" autocomplete="new-password">
<input type="password" autocomplete="new-password">
</div>
然后,对于您的真实密码字段,使用
<input type="password" name="password" autocomplete="new-password">
如果这不再工作,或如果您遇到其他浏览器或版本的问题,请注释此答案。
批准:
Chrome浏览器:49 Firefox: 44,45 边缘:25 Internet Explorer: 11
对于这个问题,我有一个近乎完美的解决方案: 从所有密码输入元素中删除"type=password",在所有这些元素都加载到DOM后,给一个超时来设置"type=password"。Chrome会忽略 改变类型为自动填充。例子:
setTimeout(()=>{ele.type="password"},3000)
或者通过事件改变类型:
ele.oninput=function(){ele.type="password"}
将输入类型属性更改为type="search"。
谷歌不会对输入的搜索类型应用自动填充。