Detecting Browser Autofill

前端 未结 29 1422
天涯浪人
天涯浪人 2020-11-22 06:15

How do you tell if a browser has auto filled a text-box? Especially with username & password boxes that autofill around page load.

My first question is when does

29条回答
  •  情深已故
    2020-11-22 06:56

    I used the blur event on the username to check if the pwd field had been auto-filled.

     $('#userNameTextBox').blur(function () {
            if ($('#userNameTextBox').val() == "") {
                $('#userNameTextBox').val("User Name");
            }
            if ($('#passwordTextBox').val() != "") {
                $('#passwordTextBoxClear').hide(); // textbox with "Password" text in it
                $('#passwordTextBox').show();
            }
        });
    

    This works for IE, and should work for all other browsers (I've only checked IE)

提交回复
热议问题