【问题标题】:autocomplete="off" not working for Google Chromeautocomplete="off" 不适用于谷歌浏览器
【发布时间】:2014-10-03 10:27:38
【问题描述】:

这个问题过去曾被问过好几次,但不幸的是,我无法禁用 Google Chrome (v.36.0.1985.125 m) 的自动填充功能

我已经试过了

"AutoComplete=Off" not working on Google Chrome Browser

How do I stop Chrome from pre-populating input boxes?

how to disable google chrome suggestion list when using twitter bootstrap typeahead?

到目前为止测试的代码

<form autocomplete="off">

<asp:textbox autocomplete="off">

AutoCompleteType="Disabled"

但我仍然在我的登录页面上获得自动归档的数据。即使更改了文本框 ID,也会填充密码。

【问题讨论】:

标签: asp.net visual-studio autocomplete


【解决方案1】:

由于我一直遇到同样的问题,并且似乎所有“替代方案”都停止工作,因为浏览器一直在获得最近的更新,所以我遇到了一个让我完全困惑的“肮脏”解决方案。

如果我们要禁用自动完成功能并将其自动完成属性设置为无效值(只有“off”和“on”有效)的每个字段,浏览器将因此停止尝试自动填充这些字段.

惊讶吗?我也是!

例子:

<input type="text" autocomplete="stopdoingthat" />

显然它有效。愚蠢,我知道,但它是一个“肮脏”的,现在确实有效。

【讨论】:

  • 这对我来说可以停止在 chrome 上自动填充,而我发现没有其他方法起作用。谢谢!!
  • 请参阅评论 164 以了解为什么这样做有效(以及为什么 Google 再次采取令人讨厌的“我们比你更了解”的立场……感觉就像 IE 时代,不是吗? ?) chromium bug 468153 comment 164
【解决方案2】:

无论Autocomplete=off 是什么,最新版本的谷歌浏览器都强制自动填充。您将需要一点技巧。以前的一些 hack 不再起作用(34+ 版本)

我在 Google Chrome v36 上测试了以下代码。

它从元素中删除“name”和“id”属性,并在 1ms 后将它们分配回来。这在我的情况下非常有效。

将此代码放入准备好的文档中。

 $(document).ready(function () {

$('form[autocomplete="off"] input, input[autocomplete="off"]').each(function () {

                var input = this;
                var name = $(input).attr('name');
                var id = $(input).attr('id');

                $(input).removeAttr('name');
                $(input).removeAttr('id');

                setTimeout(function () {
                    $(input).attr('name', name);
                    $(input).attr('id', id);
                }, 1);
            });
         });;

【讨论】:

    【解决方案3】:

    这个只读修复对我有用:

    修复浏览器自动填充:只读并在焦点上设置可写(在鼠标单击和选项卡中通过字段)

     <input type="password" readonly  
         onfocus="$(this).removeAttr('readonly');"/>
    

    顺便说一下,关于 Chrome 和 Safari 自动填充行为的更多信息

    有时即使 autocomplete=off 也不会阻止将凭据填写到错误的字段中,但不会阻止用户或昵称字段。我猜,Chrome 和 Safari 会寻找密码字段来插入您保存的凭据。然后它username 自动填充到最近的 textlike-input 字段中,该字段出现在 DOM 中的密码字段之前(只是由于观察而猜测)。由于浏览器是最后一个实例,您无法直接控制它,但上面的只读技巧修复了它。 :-)

    【讨论】:

    • 对我不起作用,Chrome 版本 69.0.3497.100(官方构建)(64 位)
    【解决方案4】:

    我想我会用 2016 年的帖子更新这个。我使用了Sangram 的解决方案和dsuess' 的组合。截至本文发布之时,这对我有用。

    不幸的是,Sangram 的解决方案在更高版本的 Chrome 版本中不再适用于我,而是使用 dsuess 将字段标记为只读的方法,同时在视觉上不吸引人(因为它们一直保持只读状态,直到您真正关注元素,这不是最直观的方法 - 但不管用什么方法,对吧?),仍然有效。

    通过将两者结合起来,我们不再需要用户专注于该领域。这是我的网页代码:

    <asp:TextBox ID="TeamName" runat="server" TextMode="SingleLine" AutoCompleteType="Disabled" ReadOnly="true"></asp:TextBox>
    

    对于好奇的人,它在被 IIS 解析后呈现为以下原始 HTML:

    <input name="ctl00$MainContent$uc_CreateTeam$TeamName" type="text" autocomplete="off" id="MainContent_uc_CreateTeam_TeamName" readonly="readonly">
    

    随附的js:

    // Disable autocomplete for form fields. This is done by setting the 'autocomplete' attribute (which is deprecated)
    // as an indicator that we want this field to not be autofilled. We also set these forms to load as readonly (which
    // will cause browsers to ignore them), and now we mark them writable.
    $(document).ready(function() {
      $('form[autocomplete="off"] input, input[autocomplete="off"]').each(function() {
        var input = this;
        setTimeout(function() {
          $(input).removeAttr('readonly');
        }, 200); // 100 does not work - too fast.
      });
    });

    希望这对几年后仍在寻找解决方案的落后者有所帮助!

    【讨论】:

      【解决方案5】:

      听着,解决此问题的唯一方法是向 Chromium 开发人员请愿。上他们的论坛,告诉他们这是多么痛苦。每个解决方法最终都会被他们破坏。

      https://bugs.chromium.org/p/chromium/issues/detail?id=914451

      截至目前,在控件上使用唯一 ID 可以解决此问题。

      我的建议是使用用户的会话 ID 作为页面上控制 ID 的一部分。目前,这在所有方面都有效。但它不会永远。

      【讨论】:

        【解决方案6】:

        将密码字段的类型设为“文本”并在点击时将其更改为“密码”。

        HTML:

        <input autocomplete="off" id='username'>
        <input autocomplete="off" id='password' type="text" onclick="changeType('password')">
        

        js:

        changeType(id) {
            document.getElementById(id).setAttribute('type', 'password');
        }
        

        【讨论】:

          【解决方案7】:

          对于 Asp.Net TextBox,添加 TextMode="Search" 和 AutoCompleteType="Disabled" 对我有用

          <asp:TextBox runat="server" ID="txtAddress" CssClass="form-control" TextMode="Search" AutoCompleteType="Disabled"></asp:TextBox>
          

          我在 Edge(89.0.774.48 版)和 Chrome(88.0.4324.190 版)中都对此进行了测试

          【讨论】:

            【解决方案8】:

            为我工作:

            <asp:TextBox ID="TextBox"  runat="server" Text='mootez'onfocus="this.autocomplete='off'" ></asp:TextBox>  
            
                                                                                     
            

            【讨论】:

            • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
            • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
            【解决方案9】:

            我的建议是更改控件的名称。例如,我有一个名为 txtFirsName 的控件,它总是向我显示自动完成建议,我将其更改为 txtFN 和 Ready!

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2019-12-13
              • 2012-09-19
              • 2018-04-28
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-11-06
              相关资源
              最近更新 更多