首页 > 解决方案 > Firefox 自动填充/自动完成不断填写新的用户名/密码表单

问题描述

我正在尝试创建一个表单,管理员用户可以在其中创建一个新用户并为其设置密码,但 Firefox 会继续使用最初登录的用户凭据填写这些表单元素。

这就是我的 html 的样子:

<input id="account-un" class="new-user-name" type="text" placeholder="Please set a password for this account" value="" autocomplete="off">
<input id="account-psw" class="new-user-password" type="password" placeholder="Please set a password for this account" value="" autocomplete="new-password">

autocomplete="off"在这两个领域都尝试过,但似乎没有任何效果。有什么方法可以防止 Firefox 或/和任何其他浏览器自动填充这些表格?

我正在使用 Firefox 63.0.3

标签: htmlfirefoxautocomplete

解决方案


我没有检查过,但你可以试试这个旧的解决方案:

     if (document.getElementsByTagName) {

    var inputElements = document.getElementsByTagName(“input”);

    for (i=0; inputElements[i]; i++) {

    if (inputElements[i].className && (inputElements[i].className.indexOf(“disableAutoComplete”) != -1)) {

    inputElements[i].setAttribute(“autocomplete”,”off”);

}

}

}

来源:https ://css-tricks.com/snippets/html/autocomplete-off/#comment-88998


推荐阅读