如何触发保存的密码自动填充在浏览器? [英] How to trigger saved password autofill in browsers?

查看:423
本文介绍了如何触发保存的密码自动填充在浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序写在纯JavaScript(除了加载所有的JS文件的文件没有pre-生成的HTML)。

I have a web application written in pure JavaScript (no pre-generated HTML except for the document which loads all the JS files).

该应用程序包含了动态创建在触发事件的document.ready事件登录表单。我欺骗浏览器显示记住密码?通过张贴登录表单到一个隐藏的iframe中使用AJAX记录(在Firefox则口令保存的密码列表中,因此这部分显然工程),但保存的密码永远无法登录界面后,填写在以后再次加载对话框时间。同样的事情发生在Firefox和Safari。

This app contains a login form which is created dynamically when the document.ready event event is triggered. I trick the browser into displaying the "Remember password?" dialog by posting the login form into a hidden iframe before logging in using ajax (in Firefox the password appears on the saved password list, so this part obviously works) but saved passwords never get filled in after the login screen is loaded again at a later time. The same thing happens in Firefox and Safari.

有什么我可以做或某些功能,我可以打电话来触发自动填充?

Is there something I can do or some function I can call to trigger autofill?

更新:自动填写作品在Safari上的初始页面加载,而不是在用户注销和登录表单无需重新加载页面重新创建。在Firefox它永远不会工作的。

UPDATE: autofill works in Safari on initial page load, but not when user logs out and the login form is recreated without a page reload. In Firefox it never works.

推荐答案

在除了包装在格式元素中的表单元素,确保所有的输入(也许连形式)具有独特的名称 ID 属性不会改变。名字大概应该是这样的密码什么的描述输入密码等等,真的不知道学位的浏览器使用此信息,但自动提示/魔棒功能可能更好地工作,如果你使用一个标准的名称。

In addition to wrap the form elements in a form element, make sure all the input (and maybe even the form) has unique name and id attributes that doesn't change. The name should probably be something descriptive like password for the password etc., not really sure to which degree browsers use this info, but "autosuggest"/"magic wand" features may work better if you use a standard name.

当然,你要确保你没有设置任何自动提示/自动填充属性为false(JS框架可能出于某种原因这样做,如果你使用任何)。

And of course you should make sure you're not setting any autosuggest/autofill attributes to false (the js framework might do so for some reason, if you're using any).

第三种可能性是,一些浏览器也许你的脚本加载之前自动填充不和写入形式的页面,请尝试以下形式的静态的HTML版本,看看是否的的工作。

A third possibility is that some browsers maybe does autofill before your script loads and writes the form to the page, try making a static html version of the form and see if that works.

最简单的解决方案(如静态形式的工作)是强行注销页面重载(你也许想注销后丢弃的运行的JavaScript的状态无论如何,所以刷新真的是一件好事)

The easiest solution (if static forms work) is to force a page reload on logout (you probably do want to discard the "state" of the running javascript after log-out anyway, so refreshing is really a Good Thing)

这篇关于如何触发保存的密码自动填充在浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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