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 this occur in the page load sequence? Is it before or after document.ready?
Secondly how can I use logic to find out if this occurred? Its not that i want to stop this from occurring, just hook into the event. Preferably something like this:
if (autoFilled == true) {
} else {
}
If possible I would love to see a jsfiddle showing your answer.
Possible duplicates
DOM event for browser password autofill?
Browser Autofill and Javascript triggered events
--Both these questions don't really explain what events are triggered, they just continuously recheck the text-box (not good for performance!).
I used this solution for same problem.
HTML code should change to this:
and jQuery code should be in
document.ready
:I was looking for a similar thing. Chrome only... In my case the wrapper div needed to know if the input field was autofilled. So I could give it extra css just like Chrome does on the input field when it autofills it. By looking at all the answers above my combined solution was the following:
The html for this to work would be
On chrome, you can detect autofill fields by settings a special css rule for autofilled elements, and then checking with javascript if the element has that rule applied.
Example:
CSS
JavaScript
I was reading a lot about this issue and wanted to provide a very quick workaround that helped me.
where
inputBackgroundNormalState
for my template is 'rgb(255, 255, 255)'.So basically when browsers apply autocomplete they tend to indicate that the input is autofilled by applying a different (annoying) yellow color on the input.
Edit : it will work for every browser
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.
Here is a link for the issue in chromium. https://bugs.chromium.org/p/chromium/issues/detail?id=636425
I have perfect solution for this question try this code snippet.
Demo is here