浏览器如何知道何时提示用户保存密码? [英] How does browser know when to prompt user to save password?
问题描述
这与我在这里问的问题有关:如何让浏览器提示保存密码?
This is related to the question I asked here: How can I get browser to prompt to save password?
这就是问题所在:我无法让浏览器提示我保存我正在开发的网站的密码.(我指的是当您在 Firefox 上提交表单时有时会出现的栏,上面写着记住 yoursite.com 的密码?是/不是现在/从不")
This is the problem: I CAN'T get my browser to prompt me to save the password for the site I'm developing. (I'm talking about the bar that appears sometimes when you submit a form on Firefox, that says "Remember the password for yoursite.com? Yes / Not now / Never")
这非常令人沮丧,因为 Firefox(以及大多数其他现代浏览器,我希望它们以类似的方式工作)的这个功能似乎是个谜.这就像浏览器做的一个魔术,它查看你的代码,或者你提交的内容,或者其他东西,如果它看起来"像一个带有用户名(或电子邮件地址)字段和密码字段的登录表单,它会提供保存.
This is super frustrating because this feature of Firefox (and most other modern browsers, which I hope work in a similar fashion) seems to be a mystery. It's like a magic trick the browser does, where it looks at your code, or what you submit, or something, and if it "looks" like a login form with a username (or email address) field and a password field, it offers to save.
除非在这种情况下,在我的用户使用我的登录表单后它没有为我的用户提供该选项,这让我很抓狂.:-)
Except in this case, where it's not offering my users that option after they use my login form, and it's making me nuts. :-)
(我检查了我的 Firefox 设置——我没有告诉浏览器从不"这个网站.它应该是提示.)
(I checked my Firefox settings-- I have NOT told the browser "never" for this site. It should be prompting.)
Firefox 使用什么启发式方法来知道何时应该提示用户保存?这应该不难回答,因为它就在 Mozilla 源代码中(我不知道去哪里寻找,否则我会尝试自己挖掘它).我也没有找到 Mozilla 开发人员关于此问题的博文或其他类似的开发人员说明.
What are the heuristics that Firefox uses to know when it should prompt the user to save? This shouldn't be too difficult to answer, since it's right there in the Mozilla source (I don't know where to look or else I'd try to dig it out myself). I've also had no luck finding a blog post or some other similar developer note from the Mozilla developers about this.
(我可以为 Safari 或 IE 回答这个问题;我想所有浏览器都使用非常相似的规则,所以如果我可以在其中一个中使用它,它也可以在其他浏览器中使用.)
(I would be fine with this question being answered for Safari or IE; I would imagine that all the browsers user very similar rules, so if I can get it working in one of them, it will work in the others.)
(* 请注意,如果您对我的回答与 cookie、加密或其他任何有关我如何在本地数据库中存储密码的问题有关,那么您很可能误解了我的问题.:-)
(* Note that if your answer to me has anything to do with cookies, encryption or anything else that is about how I'm storing passwords in my local database, odds are strong that you have misunderstood my question. :-)
推荐答案
根据我阅读的内容,我认为 Firefox 通过 form.elements[n].type == "password"
检测密码(遍历所有表单元素)然后通过向后搜索密码字段之前的文本字段的表单元素来检测用户名字段(更多信息 此处).您可以在 Javascript 中尝试类似的操作,看看是否可以检测到您的密码字段.
Based off what I have read, I think Firefox detects passwords by form.elements[n].type == "password"
(iterating through all form elements) and then detects the username field by searching backwards through form elements for the text field immediately before the password field (more info here). You might try something similar in Javascript and see if you can detect your password field.
据我所知,您的登录表单必须是 的一部分,否则 Firefox 将无法检测到它.在您的密码字段上设置
id="password"
可能也不会受到伤害.
From what I can tell, your login form needs to be part of a <form>
or Firefox won't detect it. Setting id="password"
on your password field probably couldn't hurt either.
如果这仍然给您带来很多问题,我建议您在 Mozilla 项目的开发人员邮件列表之一上询问(您甚至可能会收到设计该功能的开发人员的回复).
If this is still giving you a lot of problems, I would recommend asking on one of the Mozilla project's developer mailing lists (you might even get a response from the developer who designed the feature).
这篇关于浏览器如何知道何时提示用户保存密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!