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

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

问题描述

我有一个用纯 JavaScript 编写的 Web 应用程序(除了加载所有 JS 文件的文档,没有预先生成的 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 事件事件时动态创建.我欺骗浏览器显示记住密码?"通过在使用 ajax 登录之前将登录表单发布到隐藏的 iframe 中(在 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.

推荐答案

除了将表单元素包裹在 form 元素中之外,还要确保所有输入(甚至表单)都具有唯一性nameid 属性不会改变.该名称可能应该是描述性的,例如密码等的 password,不确定浏览器使用此信息的程度,但是如果您使用自动建议"/魔杖"功能可能会更好标准名称.

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.

当然,您应该确保没有将任何 autosuggest/autofill 属性设置为 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天全站免登陆