在 Chrome 浏览器中,我已经保存了用户名和密码。
现在,如果我导航到其他表单并且它包含其他一些东西的用户名和密码,我保存的那个会自动填充到这里。
我怎样才能阻止这个?
在 Chrome 浏览器中,我已经保存了用户名和密码。
现在,如果我导航到其他表单并且它包含其他一些东西的用户名和密码,我保存的那个会自动填充到这里。
我怎样才能阻止这个?
当autocomplete=off
不会阻止填写凭据时,请使用以下内容 -
修复浏览器自动填充:只读并将 writeble 设置为焦点(单击和选项卡)。
<input type="password" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly','');"/>
对于火狐浏览器使用这个:
<input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" />
<input type="password" name="password_fake" id="password_fake" value="" style="display:none;" />
<input type="password" name="password" id="password" value="" />
对于 Chrome 浏览器:使用autocomplete="new-password"
请参考以下内容:
https ://www.chromium.org/developers/design-documents/create-amazing-password-forms
和https://www.chromium.org/developers/design-documents/form-styles-那铬明白
尝试以下操作:
<form id="login" action="signup.php" method="post">
<input type="text" autocomplete="username">
<input type="password" autocomplete="new-password">
<input type="password" autocomplete="new-password">
<input type="submit" value="Sign Up!">
</form>
<textarea required="required" autocorrect="off" autocapitalize="off" name="username" class="form-control" placeholder="Your username" rows="1" cols="20" wrap="off"></textarea>
<textarea required="required" autocorrect="off" autocapitalize="off" name="password" class="form-control password" placeholder="Your password" rows="1" cols="20" wrap="off"></textarea>
@font-face {
font-family: 'password';
src: url('css/font/password.woff2') format('woff2'),
url('css/font/password.woff') format('woff'),
url('css/font/password.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
textarea.form-control {
overflow:hidden;
resize:none;
height:34px;
}
textarea.form-control.password:valid {
font-family: 'password';
}
笔记
最后,它最终变成了一堆骇人听闻的黑客攻击(但它确实有效)
首先尝试将密码字段设置为
autocomplete="new-password"
上述解决方案应停止自动填写用户名和密码
注意:有时在用户名和密码上设置 autocomplete="off" 可能不起作用