How to prevent a browser from storing passwords with HTML and JavaScript?

Spread the love

To prevent a browser from storing passwords with HTML and JavaScript, we set the autocomplete attribute to off and change the readonly attribute dynamically.

For instance, we write

<input
  type="text"
  name="username"
  autocomplete="off"
  readonly
  onfocus="this.removeAttribute('readonly');"
/>

to set the autocomplete attribute to off.

And we set the onfocus attribute to JavaScript code that calls removeAttribute on the element to remove the readonly attribute when we focus on it.

Leave a Reply

Your email address will not be published. Required fields are marked *