Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell Firefox not to remember the state of my input fields on page refresh?

Tags:

html

firefox

Firefox has a very annoying feature. It remembers the state of input fields when you hit F5. It's not just the value, it remembers even whether the input is disabled or not.

Example:

<html>
    <head>
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    </head>
    <body>
        <input type="text" value="textbox" />
        <a href="#" onclick="javascript: $('input').attr('disabled', true); return false; " >Disable text box</a>
    </body>
</html>

The code above has an anchor that, when clicked, disables the text input field. After that, Firefox will remember the state after F5 and the only way to restore it to the original is to hit enter on the address bar.

Is there a meta tag or something to make FF stop doing that?

EDIT

Actually browsers have different behaviors. Firefox is the most annoying. Firefox remembers the input value and whether it's disabled or not. IE8 remembers the value and Chrome doesn't remember anything

like image 907
André Pena Avatar asked Nov 29 '11 13:11

André Pena


2 Answers

You can set the element or the form to autocomplete="off" to disable state preservation, but that also disables input autocomplete, of course.

like image 131
Boris Zbarsky Avatar answered Nov 12 '22 21:11

Boris Zbarsky


I do think all browsers have that feature.

But to reset your input to its original value, try this.

$('document').ready(function(){//or whenever you want to fire back to the default value
    $('input#withanidplease').val($('input#withanidplease').prop('defaultValue'))
})
like image 36
Fredy31 Avatar answered Nov 12 '22 22:11

Fredy31