Detecting Browser Autofill

前端 未结 29 1830
天涯浪人
天涯浪人 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:46

    From my personal experience, the below code works well with firefox IE and safari, but isn't working very well at picking autocomplete in chrome.

    function check(){
    clearTimeout(timeObj);
     timeObj = setTimeout(function(){
       if($('#email').val()){
        //do something
       }
     },1500);
    }
    
    $('#email').bind('focus change blur',function(){
     check();
    });
    

    Below code works better, because it will trigger each time when user clicks on the input field and from there you can check either the input field is empty or not.

    $('#email').bind('click', function(){
     check();
    });
    

提交回复
热议问题