检测浏览器自动填充 [英] Detecting Browser Autofill

查看:184
本文介绍了检测浏览器自动填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断浏览器是否自动填充文本框?特别是用户名和密码框自动填充页面加载。



我的第一个问题是什么时候在页面加载序列中发生?是否在document.ready之前或之后?



其次,如何使用逻辑来确定是否发生了这种情况?它不是我想阻止这种发生,只是钩在事件。最好是这样的:

  if(autoFilled == true){

} else {

}

如果可能,我希望看到一个jsfiddle显示你的答案。 / p>

可能的重复



浏览​​器密码自动填充的DOM事件



浏览器自动填充和Javascript触发的事件



- - 这些问题并不能真正解释什么事件被触发,他们只是不断重新检查文本框(对性能不好)。

解决方案

自动填充的问题由不同的浏览器处理不同。有些调度更改事件,有些不行。因此,当浏览器自动填充输入字段时,几乎不可能挂起触发的事件。




  • 更改不同的事件触发器浏览器:




    • 对于用户名/密码字段:


      1. Firefox 4,IE 7和IE 8不会发送更改事件。

      2. Safari 5和Chrome 9会调度更改事件。


    • 对于其他表单字段:


      1. IE 7和IE 8不派发更改事件。

      2. 当用户从一个建议列表中选择一个值并将其从该字段中选出时,Firefox 4将调度更改事件。

      3. Chrome 9不调度更改事件。

      4. Safari 5将发送更改事件。





最好的选择是使用禁用窗体的自动填充autocomplete =off在您的表格或轮询定期间隔t o看看是否填写。



对于您是否在document.ready之前或之前填写的问题,浏览器甚至版本也不同。仅当您选择用户名密码字段时,才能使用用户名/密码字段。所以如果你尝试附加到任何事件,你会有一个非常混乱的代码。



你可以在这个 HERE


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!).

解决方案

The problem is autofill is handled differently by different browsers. Some dispatch the change event, some don't. So it is almost impossible to hook onto an event which is triggered when browser autocompletes an input field.

  • Change event trigger for different browsers:

    • For username/password fields:

      1. Firefox 4, IE 7, and IE 8 don't dispatch the change event.
      2. Safari 5 and Chrome 9 do dispatch the change event.

    • For other form fields:

      1. IE 7 and IE 8 don't dispatch the change event.
      2. Firefox 4 does dispatch the change change event when users select a value from a list of suggestions and tab out of the field.
      3. Chrome 9 does not dispatch the change event.
      4. Safari 5 does dispatch the change event.

You best options are to either disable autocomplete for a form using autocomplete="off" in your form or poll at regular interval to see if its filled.

For your question on whether it is filled on or before document.ready again it varies from browser to browser and even version to version. For username/password fields only when you select a username password field is filled. So altogether you would have a very messy code if you try to attach to any event.

You can have a good read on this HERE

这篇关于检测浏览器自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆