var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
inputs[i].onfocus = foo;
}
function foo(){
alert(this.value);
}
When the input values are manually entered:
Above code works and alerts the correct values regardless of the type of an input field.
When the input values auto-filled by browser:
Code works and alerts the correct values when the input field is of type text. In case of a password field, it alerts empty string!
Is this behaviour because of the browser's security policies? Or there's any workaround possible? I tried it in Chrome browser.
The maxLength property sets or returns the value of the maxlength attribute of a password field. The maxlength attribute specifies the maximum number of characters allowed in a password field. Tip: To set or return the width of a password field, in number of characters, use the size property.
<input type="password"> <input> elements of type password provide a way for the user to securely enter a password.
$(document).ready(function() {
$("input")
.blur(password)
.trigger('blur');
});
function password() {
alert($(this).val())
}
DEMO
This is an interesting question because I believe that you are referring to the side-effect of a security feature in Chrome.
Chrome (and probably other browsers) may not actually populate the DOM with the auto-filled password because a malicious programmer could write a JavaScript that attempts to steal auto-filled passwords from unsuspecting victims once a page loads.
You will most likely require that the user clicks a submit button before you can gain access to that information.
You might be able to force the form to submit and check the value right before the submit actually occurs. If that works, then you can just cancel the submission by returning false in "onsubmit" and you now have the password.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With