【发布时间】:2021-08-14 12:36:33
【问题描述】:
我正在通过使用 javascript 填写 Web 应用程序的用户名和密码来开发自动登录功能。密码字段已激活自动完成功能。它的 HTML 如下 -
<input name="autofill_password" type="password" style="display:none">
<input name="user_password" type="text" onfocus="this.setAttribute('type', 'password')" id="user_password" maxlength="256" class="loginField" autocomplete="new-password">
我无法使用 javascript 或 jquery 为“user_password”字段设置值。 我试过以下没有运气 -
$('#user_password').val("g");
$('#user_password').attr('value', 'new value');
document.getElementById('user_password').value = 'Welcome!1';
document.getElementById('user_password').setAttribute('type', 'text');
是什么阻止了该值的设置,我还能尝试什么?
【问题讨论】:
-
您显示的代码可以正常工作:jsfiddle.net/RoryMcCrossan/1o5hztg9。检查控制台是否有错误
-
此外,在客户端 JS 的密码字段中设置自动编译功能对于安全性来说似乎是一个非常糟糕的主意。
-
@RoryMcCrossan just to showcase that all three approaches work
-
密码字段的自动完成可能会很复杂并且特定于浏览器。为什么不使用 Lastpass 等浏览器和插件中已经内置的自动完成功能?
-
实际上我们正在尝试自动化导航和输入到一个无法访问源代码的门户
标签: javascript jquery jquery-ui cefsharp jquery-widgets