Aivan Monceller
Aivan Monceller

Reputation: 4680

Bypass refresh behavior of Firefox

How do you capture refresh button or event of Firefox browser using Javascript and imitate the behavior of IE when refreshing forms? Firefox refills the forms which destroys my ajax UI.

Upvotes: 5

Views: 518

Answers (3)

Aivan Monceller
Aivan Monceller

Reputation: 4680

<form name="form1" id="form1" method="post" autocomplete="off" action="http://www.example.com">
</form>

https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion

Upvotes: 1

syockit
syockit

Reputation: 5834

I'm not sure how IE behaves, but if you just want the form to be empty before your ajax UI does its work, you can clear the form as it reloads by using window.beforeunload.

Upvotes: 1

martona
martona

Reputation: 5914

You can keep track of everything entered (onchange, etc), encode, and put it into local storage. When the page loads, see if you have anything in local storage and fill the form with the user's data.

Make sure you empty storage when needed (form submittal, onbeforeunload, after reading the data, etc.)

If the problem you're trying to solve is so narrow, you can make the data very short-lived in storage too. Also, make it session-only if you can. You can also limit the saving of data to the onbeforeunload event, instead of saving on every change. At the very least, do a setTimeOut() with some reasonable amount of seconds after onchange is fired and do your saving in the setTimeOut handler, this way you won't use up CPU unnecessarily.

Upvotes: 0

Related Questions