Reputation: 61
Is there any alternative on disabling back buttons of any browser to avoid the following situation:
Upvotes: 3
Views: 395
Reputation: 30446
Check out sisyphus.js. it is exactly for this purpose. It adds GMail style (client side) auto saving to any HTML form. Add this line of JavaScript in the page with the form you want to save:
$('form').sisyphus();
As the user fills in this form the library will automatically save anything they type, locally. If they leave the page (or the browser crashes, just returning to the same page will auto populate the form with all of their data. As soon as they successfully submit the form, sisyphus.js will clear out the locally cached inputted data.
There is an alternative to Sisyphus that I have not tried yet called Garlic.js which is said to have better support for older browsers.
Upvotes: 3
Reputation: 42669
You need to track some dirty flag on the form. Browsers have a onbeforeunload
event. Subscribe to this event and popup a dialog to user whether he really wants to leave the page.
Keep in mind this event gets fired for any navigation from the page.
Upvotes: 0