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

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

问题描述

你怎么判断一个浏览器的自动填充一个文本框?特别是随着用户名和放大器;密码箱的自动填充周围的页面加载。

我的第一个问题是什么时候会发生这种情况在页面加载顺序?它是之前或之后的document.ready?

其次怎么我可以用逻辑来看看发生这种情况?它不是,我要阻止发生这一点,只是挂钩到事件。 preferably是这样的:

 如果(自动填充==真){}其他{}

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

可能的重复

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

<一个href=\"http://stackoverflow.com/questions/4938242/browser-autofill-and-javascript-triggered-events\">Browser自动填充和Javascript触发的事件

- 这两个问题没有真正解释触发什么事件,他们只是不断地重新检查文本框(!不利于性能)


解决方案

问题是自动填充是由不同的浏览器不同的处理。有些调度change事件,有些则没有。因此它几乎是不可能的钩到其被触发时浏览器自动填充的输入域的事件。


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


    • 有关用户名/密码字段:


      1. 火狐4,IE 7和IE 8不调度change事件。

      2. 5的Safari和Chrome 9千万调度change事件。


    • 有关其他表单字段:


      1. IE 7和IE 8不调度change事件。

      2. 火狐4会调度的改变而改变的事件当用户选择的建议,然后切换出该领域的列表中的值。

      3. 的Chrome 9不会调度change事件。

      4. Safari 5的会调度change事件。



您最好的选择是使用自动完成=关闭在窗体或轮询在固定时间间隔,看看它填充的形式或者禁用自动完成。

有关是否充满或再次的document.ready从浏览器到浏览器,甚至版本的升级而变化之前,你的问题。对于用户名/密码字段,只有当您选择一个用户名密码字段被填满。这么干脆,如果您尝试连接到任何情况下你将有一个非常混乱code。

您可以在此这里一个良好的阅读

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天全站免登陆