Removing input background colour for Chrome autocomplete?

前端 未结 30 1864
失恋的感觉
失恋的感觉 2020-11-22 04:02

On a form I\'m working on, Chrome is auto-filling the email and password fields. This is fine, however, Chrome changes the background colour to a pale yellow colour.

相关标签:
30条回答
  • 2020-11-22 04:31

    I give up!

    Since there is no way to change the color of the input with autocomplete I decide to disable all of them with jQuery for webkit browsers. Like this:

    if (/webkit/.test(navigator.userAgent.toLowerCase())) {
        $('[autocomplete="on"]').each(function() {
            $(this).attr('autocomplete', 'off');
        });
    }
    
    0 讨论(0)
  • 2020-11-22 04:32

    Adding one hour delay would pause any css changes on the input element.
    This is more better rather than adding transition animation or inner shadow.

    input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill{
      transition-delay: 3600s;
    }
    
    0 讨论(0)
  • 2020-11-22 04:34

    This has been as designed since this coloring behavior has been from WebKit. It allows the user to understand the data has been prefilled. Bug 1334

    You could turn off autocomplete by doing (or on the specific form control:

    <form autocomplete="off">
    ...
    </form
    

    Or you can change the colour of the autofill by doing:

    input:-webkit-autofill {
        color: #2a2a2a !important;
    }
    

    Note, there is a bug being tracked for this to work again: http://code.google.com/p/chromium/issues/detail?id=46543

    This is a WebKit behavior.

    0 讨论(0)
  • 2020-11-22 04:34

    All of the above answers worked but did have their faults. The below code is an amalgamation of two of the above answers that works flawlessly with no blinking.

    input:-webkit-autofill,
    input:-webkit-autofill:hover,
    input:-webkit-autofill:focus,
    input:-webkit-autofill:active {
        transition: background-color 5000s ease-in-out 0s;
        -webkit-box-shadow: 0 0 0px 1000px #fff inset;
    }
    
    0 讨论(0)
  • 2020-11-22 04:34

    The solution of Daniel Fairweather (Removing input background colour for Chrome autocomplete?) (I would love to upvote his solution, but still need 15 rep) works really good. There is a really huge difference with most upvoted solution : you can keep background images ! But a little modification (just Chrome check)

    And you need to keep in mind, it ONLY works on visible fields !

    So you if you are using $.show() for your form, you need to run this code After show() event

    My full solution (I have a show/hide buttons for login form ):

     if (!self.isLoginVisible()) {
            var container = $("#loginpage");
            container.stop();
            self.isLoginVisible(true);
            if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
    
                var documentForms = document.forms;
                for (i = 0; i < documentForms.length; i++) {
                    for (j = 0; j < documentForms[i].elements.length; j++) {
                        var input = documentForms[i].elements[j];
    
                        if (input.type == "text" || input.type == "password" || input.type == null) {
                            var text = input.value;
                            input.focus();
                            var event = document.createEvent('TextEvent');
                            event.initTextEvent('textInput', true, true, window, 'a');
                            input.dispatchEvent(event);
                            input.value = text;
                            input.blur();
                        }
                    }
                }
            }
    
        } else {
            self.hideLogon();
        }
    

    Sorry again, I would prefer it to be a comment.

    If you want, I can put a link to the site where I used it.

    0 讨论(0)
  • 2020-11-22 04:35

    I've got a solution if you want to prevent the autofill from google chrome but its a little bit "machete" , just remove the class that google chrome adds to those inputs fields and set the value to "" if you dont need to show store data after load.

    $(document).ready(function () {
        setTimeout(function () {
                var data = $("input:-webkit-autofill");
                data.each(function (i,obj) {
                $(obj).removeClass("input:-webkit-autofill");
                        obj.value = "";
                });
        },1);           
    });
    
    0 讨论(0)
提交回复
热议问题