繁体   English   中英

如何以编程方式在Chrome中隐藏密码建议列表?

[英]How to programatically hide password suggestion list in chrome?

当用户单击密码字段时,已保存的密码将在字段下方列出,如下所示。 有什么可能的方法可以隐藏此列表?

在此处输入图片说明

注意:我尝试了各种方法,例如设置输入字段属性autocomplete="new-password"并添加一个falsepassword字段。 但是仍然没有运气。 :(

我想出了一个解决此问题的方法,那就是使用JQuery进行密码屏蔽。

提示 :仅当输入框的类型为密码时,才会提示密码和填写表格。

所以我要解决的方法如下

01)。 将输入字段设置为“文本”

<input type="text" />

02)。 用'•'掩盖输入字符

 var actualPassword = [], temperoryPassword, currentCursorPosition = 0, passwordChar = '•'; $("#password-text").bind("input", function () { temperoryPassword = $(this).val(); var passwordLength = temperoryPassword.length; for (var i = 0; i < passwordLength; i++) { if (temperoryPassword[i] != passwordChar) { actualPassword[i] = temperoryPassword[i]; } } // Get current cursor position. currentCursorPosition = this.selectionStart; $(this).val(temperoryPassword.replace(/./g, passwordChar)); }); $("#password-text").bind("keyup", function () { var passwordLength = $(this).val().length; if (passwordLength < actualPassword.length) { var difference = actualPassword.length - passwordLength, key = event.keyCode || event.charCode; // Check if last keypress was backspace or delete if (key == 8 || key == 46) { actualPassword.splice(currentCursorPosition, difference); } // User highlighted and overwrite part of the password else { actualPassword.splice(currentCursorPosition - 1, difference + 1); actualPassword.splice(currentCursorPosition - 1, 0, temperoryPassword[currentCursorPosition - 1]); } } }); $("#btnSubmit").click(function(){ $("#passwordTxt").text(bindactualPassword(actualPassword)); }); // disable password cut, copy and paste function in password field $('#password-text').bind("cut copy paste",function(e) { e.preventDefault(); }); function bindactualPassword(){ return actualPassword.join(""); } 

我写了一篇有关此案的中篇文章。 您也可以在这里阅读

https://medium.com/@shamique/programatically-prevent-password-suggestion-and-auto-fill-in-browsers-6661537a3e46

希望这对其他人有用:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM