输入类型=密码值返回空,除非我在铬控制台中使用断点 [英] Input type=password value returning empty unless i use a breakpoint in the chrome console
问题描述
我试图在window.onload上获取一个密码输入框的值,但是它一直返回一个空字符串。如果我设置了一个中断点并遍历我的代码,那么它将返回正确的字符串。如果我在它之前的任何地方设置了断点,然后继续运行代码,它也可以工作。但是在没有中断点的情况下运行它,某处停止代码或者使用最长的setTimeout()似乎不起作用。
一点背景:即时编写解决方案摆脱我的铬自动完成黄色背景的设计。我发现了一个很好的解决方案,但它删除了密码值解决方案链接。所以我决定先获取密码值,然后在所有事情完成后重新设置。下面是我的代码:
window.onload = function(){setTimeout(function (){var documentForms = document.forms; //首先遍历所有形式(var i = 0; i< documentForms.length; i ++){var password = null; //现在找到密码并存储它的值for(var k = 0; k< documentForms [i] .elements.length; k ++){var passwordInput = documentForms [i] .elements [k]; if(passwordInput.type ==password){password = passwordInput (var j = 0; j< documentForms [i] .elements.length; j ++){var input = documentForms [ i] .elements [j]; if(input.type ==text|| input.type ==password|| input.type == null ){var text = input.value; input.focus(); var event = document.createEvent('TextEvent'); event.initTextEvent('textInput',true,true,window,'a'); input.dispatchEvent(事件); input.value = text; input.blur(); } //现在它已经删除了密码,如果这是密码输入,如果(input.type ==password){input.value = password; input.blur(); }}}},300);};
< form method =postclass =login> < input type =textclass =input-textname =usernameid =usernamevalue =placeholder =Email Address/> < input class =input-texttype =passwordname =passwordid =passwordplaceholder =Password/> < input type =submitclass =buttonname =loginvalue =Start/> < a href =/ forgot-password>忘记密码?< / a>< / form>
p>
Chrome假装它没有将该字段作为安全措施的值。有没有办法破解这一点。
您可以根据此问题的答案更改样式: Chrome浏览器表单自动填充及其黄色背景
I'm trying to get the value of a password input box on window.onload however it keeps returning an empty string. If I set a break point and step through my code then it returns the correct string. And if i set a breakpoint anywhere before it and then just continue running the code it will also work. But running it without a break point somewhere stopping the code at some point or even using the longest setTimeout() doesnt seem to work.
A little background: im writing a solution to rid my design of the chrome autocomplete yellow background. I found a great solution that works but it removes the password value Solution Link. So i decided to first get the password value and then reset it once everything finishes. Heres my code:
window.onload = function() {
setTimeout(function() {
var documentForms = document.forms;
//First cycle through all the forms
for (var i = 0; i < documentForms.length; i++) {
var password = null;
// Now find the password and store its value
for (var k = 0; k < documentForms[i].elements.length; k++) {
var passwordInput = documentForms[i].elements[k];
if (passwordInput.type == "password") {
password = passwordInput.value; //This keeps returning ""
}
}
// Now using this solution remove the autocomplete yellow:
for (var j = 0; j < documentForms[i].elements.length; j++) {
var input = documentForms[i].elements[j];
if (input.type == "text" || input.type == "password" || input.type == null) {
var text = input.value;
input.focus();
var event = document.createEvent('TextEvent');
event.initTextEvent('textInput', true, true, window, 'a');
input.dispatchEvent(event);
input.value = text;
input.blur();
}
// Now that it has removed the password, if this is the password input, reset its value correctly
if (input.type == "password") {
input.value = password;
input.blur();
}
}
}
}, 300);
};
<form method="post" class="login">
<input type="text" class="input-text" name="username" id="username" value="" placeholder="Email Address" />
<input class="input-text" type="password" name="password" id="password" placeholder="Password" />
<input type="submit" class="button" name="login" value="Start" />
<a href="/forgot-password">Forgotten password?</a>
</form>
Chrome pretends it does not have a value for the field as a security measure. There's no way to hack around that.
You can change the styling as per answers to this question: Google Chrome form autofill and its yellow background
这篇关于输入类型=密码值返回空,除非我在铬控制台中使用断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!