禁用自动完成在角度下不起作用。是否可以更改浏览器设置 =>关闭=>使用 Java 脚本自动完成
我已经使用了autoComplete =“ false”(“/nope/no/no new-password”)。
在FormControl和Fromgroup中,甚至我都尝试通过使用本机元素并将属性设置为False使用指令。
但是,我仍然没有解决自动填充/自动填充的解决方案。
是否可以通过使用我们的脚本将浏览器级别设置更改为关闭自动建议/自动填充的设置?
我尝试了很多,但我不能。在这里,我附上了使用表单级别和指令级别的代码。
<form [formGroup]="loginForm" autocomplete="off">
<input matInput placeholder="Username" formControlName="username" autocomplete="off">
<input matInput type="password" formControlName="password" autocomplete="new-password">
</form>
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[autocompleteOff]'
})
export class AutocompleteOffDirective {
constructor(private _el: ElementRef) {
let w: any = window;
let isChrome = w.chrome;
if (isChrome) {
this._el.nativeElement.setAttribute('autocomplete', 'off');
this._el.nativeElement.setAttribute('autocorrect', 'off');
this._el.nativeElement.setAttribute('autocapitalize', 'none');
this._el.nativeElement.setAttribute('spellcheck', 'false');
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实,很难完全关闭该产品,但是可以用
OFF WebAuthn
迫使其灭活效果,例如:来自 https://stackoverflow.com/a/a/77011536/3994745
Indeed it is difficult to completely switch off the, but it is possible to force its inactivation with
off webauthn
, example:From https://stackoverflow.com/a/77011536/3994745
恐怕Modern Browser Devs非常强烈地认为密码管理器是最安全的策略,因此您无法禁用 输入
type = password
。您可能应该只符合世界其他地方并允许用户使用密码管理器,但是如果您是某种不符合形式的反叛者,则可以制作自己的“隐藏”字体,并使用type = text = text = text
喜欢在此答案中:https://stackoverflow.com/a/22457652/12914833
:
实际上,用户可以只下载扩展程序即可使用
autoComplete = OFF
,因此您无法通过设置它提供任何安全值。这确实是用户决定是否自动填写凭证。I'm afraid modern browser devs feel very strongly that password managers are the most secure strategy and so you cannot disable them for an input of
type=password
. You should probably just conform to the rest of the world and allow the user to use a password manager, but if you're some kind of non-conformist rebel you can make your own 'hidden' font and usetype=text
like in this answer:https://stackoverflow.com/a/22457652/12914833
From the Mozilla docs:
https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#the_autocomplete_attribute_and_login_fields
Realistically, users can just download extensions to work around
autocomplete=off
so you're not providing any security value by setting it. It's really the user's decision to auto-fill their credentials or not.