Detecting Browser Autofill

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

    After research the issue is that webkit browsers does not fire change event on autocomplete. My solution was to get the autofill class that webkit adds and trigger change event by myself.

    setTimeout(function() {
     if($('input:-webkit-autofill').length > 0) {
       //do some stuff
     }
    },300)
    

    Here is a link for the issue in chromium. https://bugs.chromium.org/p/chromium/issues/detail?id=636425

提交回复
热议问题