Alternative when disabling the back button in any browser

Is there an alternative when disabling the back buttons of any browser to avoid the following situation:

  • User fills out a large form
  • The user accidentally clicks the back button
  • When the user returns to the page, they have to fill out the form again when the form has been wiped.
+3


source to share


2 answers


Check out sisyphus.js . it is exactly for this purpose. It adds automatic save GMail style (client side) to any HTML form. Add this JavaScript line to the form page you want to save:

$('form').sisyphus();

      



When the user fills out this form, the library will automatically save whatever they type locally. If they leave the page (or browser crashes, simply returning to the same page will automatically fill in the form with all their data). Once they successfully submit the form, sisyphus.js will clear the locally cached input.

There is an alternative to Sisyphus that I haven't tried yet but called Garlic.js , which is said to have better support for older browsers.

+3


source


You need to track down some dirty flag on the form. Browsers have an event onbeforeunload

. Subscribe to this event and pull a dialog to the user if he really wants to leave the page.



Remember that this event fires for any navigation from the page.

0


source







All Articles