Preventing Firefox from remembering the input value on refresh with a meta tag
Asked Answered
F

3

84

When I refresh a page with Firefox, the values of the check boxes, input fields, etc. are kept.

Is there a way to make Firefox not keep them, using a meta tag without JavaScript?

Followup answered 21/3, 2010 at 9:7 Comment(4)
Is this for your own web page or for any web page?Auspicate
Possible duplicate of Make page to tell browser not to cache/preserve input valuesLimber
Please switch to a Chromium based browser. Firefox knows about this since 21 years, and they are not able or unwilling to behave like Chrome or Safari: bugzilla.mozilla.org/show_bug.cgi?id=46845#c232Incandescent
See html - Bug With Firefox - Disabled Attribute of Input Not Resetting When Refreshing - q/5985839.Markos
F
173

For an input tag there's the attribute autocomplete you can set:

<input type="text" autocomplete="off" />

You can use autocomplete for a form too.

Frodeen answered 21/3, 2010 at 9:15 Comment(5)
This is part of HTML5 now and supported by all major browsers on <input> except Opera doesn't do the <form> tag.Subulate
For reference https://developer.mozilla.org/en-US/docs/Mozilla/How_to_Turn_Off_Form_AutocompletionFraase
@AaronD.Marasco Turning auto-complete off may also prevent Firefox from remembering input values between page reloads, but it's a valuable feature over and above remembering input values between reloads. The question was, how to stop Firefox from remembering input values between page reloads, not how to disable autocomplete.Eidson
@Mr TA... true: I suppose the answer is to use jQuery to explicitly reset the values of all INPUTs etc. on reload... I experience a very strange phenomenon with FF currently: with each reload the contents of one INPUT is "bumped along" to the next INPUT. This only happens when I have an injected <SELECT> however. I regard this autocomplete='off' solution as a temporary fix...Stolon
This is a good solution and also works for input type 'range'.Confection
A
4

If you want to prevent remembering field values after reload, while still getting to use autocomplete:

First define autocomplete off in the markup:

<input id="the-input" type="text" autocomplete="off" />

Then re-enable autocomplete programatically:

document.getElementById('the-input').autocomplete = 'on';

this will disable autocomplete just at the right time when the page loads and re-enable it so it can be used (but the field value will be empty as it should).

If it does not work for you, try wrapping the js code in a setTimeout or requestAnimationFrame.

Advocation answered 2/11, 2021 at 19:1 Comment(0)
C
1
// Internet Explorer fix - do this at the end of the page
var oninit_async_reset = setInterval(function() { resetFormIEFix(); }, 500);
function resetFormIEFix() {
    $('#inputid').val('');
    if (typeof oninit_async_reset != 'undefined')
        clearInterval(oninit_async_reset);
}
Cosme answered 7/6, 2013 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.