autocomplete= off not working in chrome
Asked Answered
G

14

11

We are working on one web application in that one payment page is there.

In that we have two Text box one is for Credit Card Number and second one is for Verification Code and it type="Password".

Now problem is when page is load in google-chrome it found type="Password" it load Save email id in Credit Card Textbox and password in Verification Code.

Now try to solve this issue i was try out something like below.

<form autocomplete="off">

<asp:textbox autocomplete="off">

This above try is not work for me. i was googling it but by luck it's not work for me.

Glassman answered 24/7, 2015 at 14:16 Comment(3)
Could also be client side cache. Try setting the appropriate expiry headers on the page to prevent Chrome from loading the page from cache/memory.Apocryphal
If your browser ignores autocomplete="off" adding a random string in place of 'off' will fix the issue. Eg, autocomplete="autocomplete_off_hack_xfr4!k"Lumbye
2024 Best Answer: https://mcmap.net/q/957415/-autocomplete-off-not-working-in-chromeMcfarlin
L
25

It appears that Chrome now ignores autocomplete="off" unless it is on the <form autocomplete="off"> tag since v34.

you can't cheat by create an hidden input over. Auto complete feature will get the first input text to fill data.

Method 1:

<form id="" method="post" action="" autocomplete="off">
    <input type="text" style="display:none" />
    <input type="password" style="display:none">
    <asp:textbox autocomplete="off">
</form>

So put this before your textbox.

<input type="text" style="display:none" />

Method 2:

Change

autocomplete="off" 

to

autocomplete="false" 

Method 3: Browser autofill in by readonly-mode.

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

Method 4:

For username password combinations. Chrome heuristics looks for the pattern.

<input type="text" onfocus="this.type='password'">

Method 5: jQuery

if ($.browser.webkit) {
    $('input[name="password"]').attr('autocomplete', 'off');
    $('input[name="email"]').attr('autocomplete', 'off');
}
Limicoline answered 24/7, 2015 at 14:23 Comment(5)
Method 3 seems to be the most reliable and standardised across browsersGuiltless
None of these methods works on Chrome for me. Version 94.0.4606.71 (Official Build) (64-bit)Dispensable
Method 1 works for chrome, but I had to add name="username" and name="password" - of course my inputs have a different id of APIUsername/APIPassword - Chrome Version 109.0.5414.75 (Official Build) (64-bit)Neritic
Nothing method working for me :(Mcfarlin
2024 Best Answer: https://mcmap.net/q/957415/-autocomplete-off-not-working-in-chromeMcfarlin
D
6

This is the only solution that worked for me with both Autocomplete and Chrome's Autofill: It works also after calling new this.props.google.maps.places.Autocomplete

  1. Add autocomplete="off" on the form tag.

  2. Set autocomplete="none" directly on the input inside the form and set the attribute again on focus.

     <form autocomplete="off">
         <input type="text" autocomplete="none" onfocus="this.setAttribute('autocomplete', 'none');"/>
     </form>
    
Danger answered 13/7, 2021 at 17:35 Comment(1)
This worked for me on latest Chrome versionPrimogenial
M
4

2024 | Best Answer!

All methods not working in 2024<=*

  • autocomplate attribute
  • type="hidden" input
  • ❌ ...

Try this:

Replace data-name as name from your input/inputs, Add JQuery codes.

Note: Before sending form, all data-name will convert to name attribute for your input ;)

<input data-name="password" />
if ($('*[data-name]').length > 0) {
    var form = $('*[data-name]').parents("form")[0];
    $(form).submit(function() {
        $.each($('*[data-name]'), function(index, element) {
            $(this).attr('name', $(this).attr("data-name"));
        });
    });
}
Mcfarlin answered 20/7 at 15:36 Comment(0)
J
1

this is works if you want to keep white as your input background color

<input type="password" class="form-control" id="password" name="password" placeholder="Password" readonly onfocus="this.removeAttribute('readonly');" style="background-color: white;">
Jaeger answered 21/12, 2016 at 7:11 Comment(0)
G
1

use this solution

<input type="password" class="form-control auto-complete-off" id="password" name="password" autocomplete="new-password">
Glarus answered 1/1, 2020 at 11:19 Comment(0)
K
1

Chrome does not support autocomplete="off" at the form level for some input fields. There are 2 solutions to do so:

  • In your form, if only two or three fields ignore autocomplete="off", then use the field name itself as the autocomplete value. i.e. autocomplete=
<form:input type="text" id="name" path="name" autocomplete="name"/>
  • Instead of defining field name manually for each field, use a script for all text typed input at the loading of the page or after.
if ($.browser.chrome) { 
    $(document).on('focus click tap', 'input', function() {
        $(this).attr("autocomplete", 'block');
    });
} else {
    $(document).on('focus click tap', 'input', function() {
        $(this).attr("autocomplete", 'off');
    });
}
Kratz answered 10/2, 2020 at 18:33 Comment(0)
T
1

this solution is no longer working in chrome 95 and above,

Try using a normal input with type text, disable copy and pasting then add a style with property -webkit-text-security to add character mask on typing

#Not that this css property is not universal as mentionned here https://developer.mozilla.org/fr/docs/Web/CSS/-webkit-text-security

Thelmathem answered 4/11, 2021 at 16:38 Comment(0)
F
0

This works well and also compatible with MDL (Material Design Light):

// Fix chrome's ignore on autocomplete=off
$('input[autocomplete=off]').each(function(){
    var copy = $(this).clone();
    copy.val('');
    copy.removeAttr('autocomplete');
    copy.insertAfter($(this));
    $(this).hide().removeAttr('required id class');
});
Federico answered 10/8, 2015 at 11:31 Comment(0)
H
0
automcomplete="off" or automcomplete="false" 

or Define autocomplete inside Input field

$('input[name="password"]').attr('autocomplete', 'off');//Disable cache
Hollands answered 10/8, 2015 at 11:35 Comment(0)
F
0

very simple, you can follow this

let elements = document.querySelectorAll('[autocomplete="off"]');
elements.forEach(element => {
    element.setAttribute("readonly", "readonly");
    element.style.backgroundColor = "inherit";
    setTimeout(() => {
        element.removeAttribute("readonly");
    }, 500);
})
Faint answered 24/9, 2020 at 5:41 Comment(0)
E
0

Is it not possible to use password type where text type is required?Regardless of the method presented above, Chrome unconditionally handles autocomplete if the name is the same. So, I used a method to randomly change the name like this.

$(document).on('focus click tap'
    , 'input[autocomplete][autocomplete!=""]:not([data-oname][data-oname!=""])'
    , function() {
    var oname = $(this).attr('name');
    var newName = "random string";  // random string
    $(this).attr({"data-oname":oname,"name":newName,autocomplete:newName});
    // A random string should be set for name and autocomplete above.
}).on('blur', 'input[data-oname][data-oname!=""]', function() {
    var oname = $(this).attr('data-oname');
    $(this).attr({"name":oname}).removeAttr('data-oname');
});
Emendate answered 16/6, 2021 at 10:41 Comment(0)
B
0

This works:

$(document).ready(function () {

    setTimeout(() => {
        $('input').attr("readonly", 'readonly');
        $('input').attr("onfocus", "this.removeAttribute('readonly')");
    }, 100);
    
});
Bashkir answered 31/7, 2021 at 12:44 Comment(0)
V
0

This is how I solved the problem.

$("body").on('focus',':input', function (e) {
    $(this).attr('autocomplete', 'off');
    $(this).attr('autocapitalize', 'off');
    $(this).attr('autocorrect', 'off');
    $(this).attr('spellcheck', 'false');
});

OR

<input type="text" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false">
Villagomez answered 10/9, 2021 at 13:47 Comment(0)
A
0

Use autocomplete="new-password" instead of autocomplete="off". This is a newer, more specific value for the autocomplete attribute, which indicates that the field is for a new password, rather than just any input. This can help prevent the browser from auto-filling the field with old passwords.

Arcane answered 19/2, 2023 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.