Skip to content

如何禁止 (表单) 用户名、密码自动填充

HTML 登录表单经常被自动填充,有的甚至用户从来没有登录过的网站也会有自动填充,甚是让人讨厌。

Mozilla developer documentation 建议使用表单设置属性 tautocomplete="off" 来阻止浏览器从 cache 获取数据填充登录表单。

html
<input type="text" name="foo" autocomplete="off" />
<input type="text" name="foo" autocomplete="off" />

但是这种方案不兼容某些 Chrome、Firefox。

最终决定使用使用隐藏 input 来接受浏览器自动填充,这样不会影响用户体验,也可以兼容所有浏览器。

html
<input style="display:none" type="password" />
<!-- for disable autocomplete on chrome -->
<input type="password" id="password" name="password" autocomplete="off" />
<input style="display:none" type="password" />
<!-- for disable autocomplete on chrome -->
<input type="password" id="password" name="password" autocomplete="off" />

最后编辑时间:

Version 4.0 (framework-1.0.0-rc.20)