Chrome Autofill/Autocomplete no value for password

后端 未结 20 1931
逝去的感伤
逝去的感伤 2020-11-27 02:57

When you have saved username and password for some site Chrome will autofill that username and password, but if you try to get the value for the password input field it is e

20条回答
  •  借酒劲吻你
    2020-11-27 03:03

    I have found a solution to this issue that works for my purposes at least.

    I have a login form that I just want to hit enter on as soon as it loads but I was running into the password blank issue in Chrome.

    The following seems to work, allowing the initial enter key to fail and retrying again once Chrome wakes up and provides the password value.

    $(function(){
    
        // bind form submit loginOnSubmit
        $('#loginForm').submit(loginOnSubmit);
    
        // submit form when enter pressed on username or password inputs
        $('#username,#password').keydown(function(e) {
            if (e.keyCode == 13) {
                $('#loginForm').submit(e);
                return false;
            }
        });
    
    });
    
    function loginOnSubmit(e, passwordRetry) {
    
        // on submit check if password is blank, if so run this again in 100 milliseconds
        // passwordRetry flag prevents an infinite loop
        if(password.value == "" && passwordRetry != true)
        {
            setTimeout(function(){loginOnSubmit(e,true);},100);
            return false;
        }
    
        // login logic here
    }
    

提交回复
热议问题