Detecting Browser Autofill

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

    Solution for WebKit browsers

    From the MDN docs for the :-webkit-autofill CSS pseudo-class:

    The :-webkit-autofill CSS pseudo-class matches when an element has its value autofilled by the browser

    We can define a void transition css rule on the desired element once it is :-webkit-autofilled. JS will then be able to hook onto the animationstart event.

    Credits to the Klarna UI team. See their nice implementation here:

    • CSS rules
    • JS hook

提交回复
热议问题