How to disable Chrome autocomplete feature?

后端 未结 6 1310
花落未央
花落未央 2021-02-19 07:09

We want to disable autocomplete in Chrome browser in our React JavaScript application. We have tried bunch of solution available on the Internet but nothing wor

相关标签:
6条回答
  • 2021-02-19 07:22

    Do autocomplete="new-password" to disable autocomplete.

    0 讨论(0)
  • 2021-02-19 07:32

    The only hack that worked for me is to create hidden input and add random number for the original input name:

    <input type="text" name="" value="" readOnly={true} style={{display: "none"}}/>
    <input
      type="text"
      name={"address " + Math.random()}
    />
    
    0 讨论(0)
  • 2021-02-19 07:40

    Nothing worked for me including new-password, so this is how I did:

    onFocus={(event) => {
      event.target.setAttribute('autocomplete', 'off');
      console.log(event.target.autocomplete);
    }}
    
    0 讨论(0)
  • 2021-02-19 07:42

    When using jsx - you have to camel case attributes; so autoComplete="new-password" instead of autocomplete.

    0 讨论(0)
  • 2021-02-19 07:43

    I got the same issue with my React project. My solution is to use a random string for autoComplete attribute. Don't use "off", as per Pim, you need to set a invalid value to really turn auto completion off. Please also note the attribute name has to be autoComplete in React.

    0 讨论(0)
  • 2021-02-19 07:44

    You can override chrome autofill by add onFocus attribute.

    render()
    {
      return <input type="text" name="name" value="this is my input" autoComplete="off" onFocus={this.onFocus} />
    }
    
    

    In the onFocus method we need to change "autocomplete" attribute through javaScript.

    onFocus = event => {
    
       if(event.target.autocomplete)
       {
         event.target.autocomplete = "whatever";
       }
    
    };
    

    This solution works for me.

    let me know if it works for you ;)

    0 讨论(0)
提交回复
热议问题