简体   繁体   English

自动完成=“关闭”跨浏览器功能

[英]Autocomplete = “off” cross browser functionality

I have a website where I have some functionality needed: 我有一个网站,其中需要一些功能:

  • No autocompletion, suggestions or saving on my site: 没有自动完成,建议或保存在我的网站上:

    • No form Fields should ever be auto-completed or have drop Down suggestions based on earlier input 任何表单字段都不应自动填写或根据先前的输入提供下拉建议
    • No form data (entries) should be saved/cached in the browser 不应在浏览器中保存/缓存任何表单数据(条目)
  • Prevent "spilling" to other sites: 防止“散布”到其他站点:

    • When visiting other websites, data from my site should not appear as suggestions in the forms (ref 1b). 当访问其他网站时,来自我网站的数据不应作为建议显示在表格中(参考文献1b)。

Up until now I have accomplished this by using autocomplete = "off" on all forms. 到目前为止,我已经通过在所有表单上使用autocomplete =“ off”来完成此操作。 Based on this link from Mozilla this should originally have the effect of solving all the issues above, but some browsers are now starting to ignore the autocomplete attribute. 根据来自Mozilla的此链接,它本来应该可以解决上述所有问题,但是现在某些浏览器开始忽略autocomplete属性。 The article referred to above states that the trick is to assign an invalid value to the attribute, such as autcomplete = "nope" 上面提到的文章指出,诀窍是为属性分配无效的值,例如autcomplete =“ nope”

My questions are: 我的问题是:

Q1: Will the solution of using autocomplete = "nope" also prevent caching/saving the data? 问题1:使用autocomplete =“ nope”的解决方案还会阻止缓存/保存数据吗?

Q2: Are there better solutions to accomplish my criteria for best cross-browser compatibility? 问题2:是否有更好的解决方案来满足我的最佳跨浏览器兼容性标准? (I have searched, but not found anything that gives me Clear answers). (我已经搜索过,但没有找到能给我明确答案的任何内容)。

The best solution is as you mentioned to put an invalid value as shown here . 最好的办法是你提到把一个无效值如图所示这里

In some cases, the browser will continue suggesting autocompletion values even if the autocomplete attribute is set to off. 在某些情况下,即使将autocomplete属性设置为off,浏览器也会继续建议自动完成值。 This unexpected behavior can be quite puzzling for developers. 对于开发人员而言,这种意外行为可能会令人困惑。 The trick to really enforcing non-autocompletion is to assign an invalid value to the attribute, for example: 真正实施非自动补全的技巧是为属性分配无效的值,例如:

autocomplete="nope"

Since this value is not a valid one for the autocomplete attribute, the browser has no way to match it, and stops trying to autocomplete the field. 由于此值对于autocomplete属性不是有效值,因此浏览器无法对其进行匹配,因此将停止尝试自动完成该字段。

Your data or cache wouldn't be affected by this and depending on what your form is built in, the data would only be saved via the form action or function handlers on the inputs . 您的数据或缓存不会受到此影响,并且取决于内置的表单,数据只能通过inputs上的form操作或function处理程序来保存。

Alternatively, I have found autocomplete= 'new-password' on the input to be reliable, however the above example on the form wrapper requires much less work than adding to every input 另外,我发现输入上的autocomplete= 'new-password'是可靠的,但是与包装到每个input上相比, form包装器上的上述示例所需的工作要少得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM