Search code examples
htmlcssinputbrowser-cache

How can I deactivate remembering values for inputs?


I have a input like this:

<input name="username" placeholder="Email" type="email" autocomplete="off" />

As you see I've set autocomplete attribute to off. But still when I open that page, the previous value is there:

enter image description here

Well how can I avoid that? Actually my problem is with ugly-background-color-input. When I change its value, it looks like this:

enter image description here

Anyway how can I deactivate caching for inputs?


Solution

  • Presumably you also a have a password field on the page? If not you can generate a random field name and get the value from the request object's key/value collection (maybe using a known prefix).

    After looking at every answer to do with disabling autocomplete and trying around 20 combinations, the following was found to work on all current browsers (including latest Firefox, Chrome, IE 11 & IE Edge)

    Place 2 dummy inputs (1 text and 1 password) with no names and no tabbing at the top of your form, but style them to be hidden (e.g. placed offscreen, but not actually display: none)

    e.g.

    <input tabindex="-1" style="left: -9999px;" type="text">
    <input tabindex="-1" style="left: -9999px;" type="password">
    

    Even the smartest browsers, which look for the first password field (regardless of its name) and attach the autocomplete to the previous input, will work with this.