简体   繁体   English

如何禁用 chrome / jquery 的自动完成和自动填充

[英]How to disable autocomplete and autofill for chrome / jquery

I want to disable both Chrome autocomplete AND Chrome autofill.我想禁用 Chrome 自动完成和 Chrome 自动填充。

I'm using JQuery UI to autocomplete an input field.我正在使用JQuery UI来自动完成输入字段。 My jquery-ui autocomplete works fine, however chrome browser displays it's own autofill on top of mine making it difficult for users to select the correct dropdown item.我的jquery-ui 自动完成工作正常,但是 chrome 浏览器在我的顶部显示它自己的自动填充,这使得用户很难 select 正确的下拉项目。

I'm using autocomplete="off" which seems to disable autocomplete for chrome but shows autofill options .我正在使用autocomplete="off"这似乎禁用了 chrome 的自动完成功能,但显示了自动填充选项

I've tried the following:我尝试了以下方法:

  • autocomplete="chrome-off" autocomplete="false" autocomplete="disabled" autocomplete="chrome-off" autocomplete="false" autocomplete="disabled"

Those attribute values ( or any invalid attribute values ) seem to be disabling the *autofill but do enable autocomplete .这些属性值(或任何无效的属性值)似乎禁用了 *autofill 但确实启用了自动完成

Important: I cannot use random name attributes since I am performing ajax requests for my own jquery-ui autocomplete重要提示:我不能使用随机名称属性,因为我正在为我自己的 jquery-ui 自动完成执行 ajax 请求

autocomplete="off"自动完成=“关闭”

doesn't work anymore.不再起作用了。 The only thing which works from 2019 is从 2019 年开始唯一有效的是

autocomplete="new-password"自动完成=“新密码”

I finally found a solution by combining a few different answers.我终于通过结合几个不同的答案找到了解决方案。

STEP 1步骤1

In order to fix the autocomplete issue, you can add a dummy invisible input field as mentioned here .为了解决自动完成问题,您可以添加一个虚拟的不可见输入字段,如此所述。 So your html should look something like this:所以你的 html 应该是这样的:

<input id="dummy_location" type="search" name="dummy_location" style='display: none;'>
<input id="location" type="search" name="location">

This will cause chrome autofill pop-up这将导致 chrome 自动填充弹出窗口

STEP 2第2步

To disable the autofill pop-up, we need to add an invalid value for the autocomplete attribute like this.要禁用自动填充弹出窗口,我们需要像这样为自动完成属性添加一个无效值。

$("#fromcity_ac").attr({
     autocomplete: "chrome-off",
});

YOU CAN STOP HERE .你可以在这里停下来

Chrome will work fine, however, autocomplete issue will pop up on other browsers such as firefox. Chrome 可以正常工作,但是,自动完成问题会在其他浏览器上弹出,例如 firefox。 To fix this you can edit step 2 by checking what browser is being used and setting an appropriate value for the autocomplete attribute.要解决此问题,您可以通过检查正在使用的浏览器并为 autocomplete 属性设置适当的值来编辑步骤 2

 var isChromium = window.chrome; var winNav = window.navigator; var vendorName = winNav.vendor; var isOpera = typeof window.opr;== "undefined". var isIEedge = winNav.userAgent;indexOf("Edge") > -1. var isIOSChrome = winNav.userAgent;match("CriOS"); // Autocomplete default value var autocomplete = "chrome-off". if (isIOSChrome) { // is Google Chrome on IOS } else if ( isChromium;== null && typeof isChromium !== "undefined" && vendorName === "Google Inc." && isOpera === false && isIEedge === false ) { // Is google chrome } else { // Is firefox autocomplete = "off"; }

autocomplete="off" to autocomplete="random-value" . autocomplete="off"autocomplete="random-value" This is the temporary fix for now.这是目前的临时修复。

try this, this works for chrome试试这个,这适用于 chrome

autocomplete="chrome-off"

As of early 2022 this seems to work:截至 2022 年初,这似乎有效:

autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="" role="combobox" spellcheck="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="" role="combobox" spellcheck="false"

It is the technique used on the google home page search box.这是谷歌主页搜索框上使用的技术。

I can confirm that Ryan's answer "As of early 2022 this seems to work" works for me (thank you, Ryan).我可以确认 Ryan 的回答“截至 2022 年初,这似乎有效”对我有用(谢谢,Ryan)。 I am using a Kendo UI AutoComplete widget and up until now (2022-02-02), this is the only thing that works, and this problem has bugged me for years.我正在使用 Kendo UI AutoComplete 小部件,直到现在 (2022-02-02),这是唯一有效的方法,这个问题困扰了我多年。

Not able to upvote, as don't have the points:-/无法投票,因为没有积分:-/

I get Google's wish to provide a good and useful UX for end users, but as developers, we need to be able to say that sometimes, it isn't what we want, at least in our humble opinions.我明白谷歌希望为最终用户提供一个好的和有用的用户体验,但作为开发人员,我们需要能够说有时,这不是我们想要的,至少在我们的拙见中是这样。 A fine example is when the autofill in Google Chrome obscures the AutoComplete options.一个很好的例子是当谷歌浏览器中的自动填充隐藏了自动完成选项时。

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

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