How to detect whether any form elements have been filled in via autofill?
I have a login form where I need to do the following:
- allow autofill so users who want to login without typing can continue to do so
- detect whether autofill was used on the form so when user later tries to access parts of the site which require login without autofill, I only prompt the user to login again (with a different version of the login form that instead does NOT allow autofill) i开发者_运维知识库f they used autofill on the first form
At present I haven't found a way to reliably detect whether autofill was used (IE, Firefox, Chrome, Google Toolbar, etc. --> any mechanism by which the form fields get filled out without the user typing would count here as "autofill"). So for now I'm simply letting users login the first time without autofill (since that's an important business requirement) and then prompting them to login from the autofill-disabled form when they get to a sensitive part of the site, even if they had as a matter of fact typed their username and password on the first form.
If anyone's found a reliable way to detect (not block) all forms of autofill, I'd love to hear about it.
I hate say it but, you can't and more importantly you(the developer) are not expected to be able too.
You have to imagine the auto-fill built into browsers today is the old auto-fill applications of yesteryear. They sat outside the browser DOM influence and literally polled known windows for known properties i.e. forms and sent key strokes directly as if the user had typed them.
The current browsers have auto-fill options built in but, they are still as non-standard as the old applications and as such not (reliably) detectable.
Either ignore them or always blank input fields via JavaScript.
精彩评论