Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autocomplete in chrome 66

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?

like image 606
Aman Srivastava Avatar asked May 18 '18 06:05

Aman Srivastava


4 Answers

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?

like image 191
SAMUEL Avatar answered Nov 22 '22 22:11

SAMUEL


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();  }" />
like image 31
Durgesh Dangi Avatar answered Nov 23 '22 00:11

Durgesh Dangi


$(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.

like image 42
Саша Новожилов Avatar answered Nov 22 '22 22:11

Саша Новожилов


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.

like image 43
Shiv Avatar answered Nov 22 '22 22:11

Shiv