11

Is there any way to disable autocomplete on a text field in chrome 66? I have tried a number of options like :

  1. autocomplete="off"
  2. autocomplete="false"
  3. autocomplete="disabled"
  4. autocomplete="something-new" etc.

Can anyone help me with this?

Also, one more thing does chrome automatically enables autocomplete for a username if it has a password type field below it?

Aman Srivastava
  • 111
  • 1
  • 4
  • 2
    Possible duplicate of [Disabling Chrome Autofill](https://stackoverflow.com/questions/15738259/disabling-chrome-autofill) – mahdi motamedi May 18 '18 at 06:36
  • 1
    No it's not, autofill is for password fields and autocomplete is for text fields. Also this is specifically for new version of Chrome which broke everything that used to work. See bugs https://bugs.chromium.org/p/chromium/issues/detail?id=587466 https://bugs.chromium.org/p/chromium/issues/detail?id=840820 – SSH May 22 '18 at 01:01
  • Are you having problems with the username and password field automatically filling up? Take a look at my answer [here](https://stackoverflow.com/a/32987696/2431281) to see if the issue is the same. – Keale May 29 '18 at 01:06

8 Answers8

1

I used this code and it is working for me. I hope it will also helpful for you. :) Enter your type with readonly and then below mention code.

<input readonly type="email" onfocus="if (this.hasAttribute('readonly')) {
    this.removeAttribute('readonly');
    this.blur();    this.focus();  }" />
Durgesh Dangi
  • 205
  • 1
  • 13
  • Thanks for the answer, Durgesh. But this does not seem to be working:( Can this be because of the autofocus attribute on this particular field? – Aman Srivastava May 25 '18 at 11:42
  • Yes you need to add with particular field. Replace your type to read only type with rest of the code. For example you input type=“email” then readonly type=“email” and for password “pass” – Durgesh Dangi May 26 '18 at 13:13
  • No, I don't think you got my question. I have autofocus enabled on the field. So can the autofocus attribute cause problem when I try your logic? – Aman Srivastava May 27 '18 at 07:12
1

A lot of browsers refuse to adhere to what you have mentioned - the best way is to make an element readonly and then on hover/click/blur/focus, remove readonly.

So you could give it a class such as disable_autocomplete and also make the input field readonly.

Then when the field is hovered, focussed, or clicked you can remove readonly. Optionally, add it back when unfocussed.

Shiv
  • 741
  • 1
  • 9
  • 28
1
$(document).ready(function(){ 
     $("input").val("");
});

So, Chrome just sets the value of element when autofilling them. Just try that, else you can try set some interval, wich will check value in HTML code, because Chrome not put new value to HTML code, just puts it in memory for itself.

1

I acheived the auto complete functionality to be disabled in chrome by giving

<form autocomplete="off">

and

var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
element.autocomplete = isChrome ? 'disabled' :  'off';

where isGoogleChrome is a function to find whether the browser is chrome written with help of this post.

JavaScript: How to find out if the user browser is Chrome?

samuelj90
  • 6,484
  • 2
  • 35
  • 38
0

I found something :

 <input autocomplete="off" onfocus="this.setAttribute('autocomplete', 'I don\' t want this Google');" />

Good Day Everybody

0

function annihilateChromesAutocomplete(){
 var clearAutocompleteInterval = setInterval(function(){
  var peskyAutocompletedInputs = document.querySelectorAll("input:-internal-autofill-selected");
  for(var i = (peskyAutocompletedInputs.length - 1); i > -1; i--){
   peskyAutocompletedInputs[i].value = peskyAutocompletedInputs[i].defaultValue;
  }
 }, 1);
 setTimeout(function(){
  clearInterval(clearAutocompleteInterval);
 }, 2000);
}
Aaron Plocharczyk
  • 2,403
  • 2
  • 3
  • 13
-1

Use this

$(document).ready(function(){ $("input").attr("autocomplete", "off"); });

And if the autofill is enabled in chrome you can follow these steps to turn it off:

Turning Off Autofill in Chrome

  1. Click the Chrome menu icon. (Three lines at the top right of your screen.)
  2. Click on Settings.
  3. At the bottom of the page, click “Show Advanced Settings”
  4. In the Passwords and Forms section, uncheck “Enable Autofill to fill out web forms in a single click”
Nit
  • 279
  • 5
  • 14
  • 1
    Hi Nitin,thanks for your answer. But your answer does not solve my problem as I can not follow the steps mentioned by you for turning off autofill as the website is client facing, so I can not go around turning off autofill for all the clients. – Aman Srivastava Jun 05 '18 at 16:57
-1

Check out the newest version of Chrome V.67. They have fixed that issue.

Pang
  • 8,605
  • 144
  • 77
  • 113
K.Dinh
  • 39
  • 3