How to prevent browser from caching form fields?

92,932

Solution 1

Try with autocomplete="off", but it will not work with all browsers

PS: duplicate...

Stop browser from filling textboxes with details

Make page to tell browser not to cache/preserve input values

Solution 2

just add simple script in some global JS:

$("form :input").attr("autocomplete", "off");

Solution 3

use meta in head

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">

or Use

<% Response.CacheControl = "no-cache"; %>
<% Response.AddHeader("Pragma", "no-cache"); %>
<% Response.Expires = -1; %>

microsoft

Share:
92,932
Igor
Author by

Igor

Updated on June 04, 2020

Comments

  • Igor
    Igor almost 4 years

    I have a textbox in a form field that gets populated by the user. However currently (in Firefox 10) the user can navigate away from the page, then come back, and the input will be populated with its previous value. I think this creates for a confusing user experience, and would like to prevent it.

    Is there a way to do this without manually resetting the value? I have tried changing the response to not cache as well as setting autocomplete='false' with no luck.

  • Igor
    Igor about 12 years
    Does not seem to resolve the issue in FF10.
  • soju
    soju about 12 years
    yes, you can't force a browser to do what you want ^^
  • Igor
    Igor about 12 years
    Is there a cross-browser solution other than manually clearing the value with javascript? Otherwise I might just make do with this.
  • soju
    soju about 12 years
    what is your doctype ? officialy, autocomplete attribute appears only in html5 standard... But I think you should not clear these value if the users don't want to (except for security reasons)
  • Henrik Petterson
    Henrik Petterson about 7 years
    Add this to input hidden fields as well.
  • IrishChieftain
    IrishChieftain about 6 years
    Solution 4 here worked for me cross-browser: codeproject.com/Questions/124608/How-avoid-the-cache-of-Text‌​box
  • Pyae Sone
    Pyae Sone over 4 years
    that is much faster way, thx