autocomplete=“off” not working for Google Chrome

2019-01-20 14:25发布

This question has been asked Several times in the past but unfortunately there's no way i could disable autofill for Google Chrome (v.36.0.1985.125 m)

I have already Tried

"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?

Code tested so far

<form autocomplete="off">

<asp:textbox autocomplete="off">

AutoCompleteType="Disabled"

But I still get autofiled data on my login page. Passwords are populated even if Textbox Ids are changed.

4条回答
仙女界的扛把子
2楼-- · 2019-01-20 14:39

This readonly-fix worked for me:

fix browser autofill in: readonly and set writeble on focus (at mouse click and tabbing through fields)

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

By the way, some more information on Chrome and Safari auto fill behaviour:

Sometimes even autocomplete=off would not prevent to fill in credentials into wrong fields, but not user or nickname field. I guess, the Chrome and Safari look for a password field to insert your saved credentials. Then it autofills username into the nearest textlike-input field , that appears prior the password field in DOM (just guessing due to observation). As the browser is the last instance and you can not directly control it, but the read-only trick above fixes it. :-)

查看更多
SAY GOODBYE
3楼-- · 2019-01-20 14:39

Figured I'd update this with a 2016 post. I used a combo of both Sangram's solution, as well as dsuess'. This is working for me as of the time of this post.

Sangram's solution unfortunately no longer worked for me with a later Chrome version, but using dsuess' method of marking the fields as readonly, while not visually appealing (since they stay readonly until you actually focus on the element, which isn't the most intuitive way to do it - but whatever works, right?), did still work.

By combining the two, we no longer require the user to focus on the field. Here is my web page code:

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

Which, for the curious, after being parsed by IIS, renders to the following raw HTML:

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

The accompanying 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.
  });
});

Hopefully this helps any stragglers still looking for the solution a few years later!

查看更多
我只想做你的唯一
4楼-- · 2019-01-20 14:45

Recent Version of Google Chrome are forcing Autofill irrespective of the Autocomplete=off . You are going to need little bit of hack here. Some of the previous hacks don't work anymore (34+ versions)

I have tested following code on Google Chrome v36.

It removes "name" and "id" attributes from elements and assigns them back after 1ms. This works perfectly in my case.

Put this code in document ready.

 $(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);
            });
         });;
查看更多
成全新的幸福
5楼-- · 2019-01-20 14:55

Since I have been having this very same issue and it seems all "alternatives" stopped working as the browsers have been getting recent updates, I came across a "dirty" solution that baffled me completely.

If we go on each field we want to disable the autocomplete feature and set its autocomplete attribute to an invalid value (only "off" and "on" are valid), the browser will stop trying to autofill those fields because of that.

Surprised? So was I!

Example:

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

And apparently it works. Stupid, I know, but it's a "dirty" one that actually works for now.

查看更多
登录 后发表回答