So you build the little beasty, and your cube-neighbor sits down to fill out a time-sheet. She spends 7 minutes selecting options and punching in percentages, and then realizes she wants to trim one field from 15% to 10%, clicks her mouse 4 pixels too far to the right putting the page, and not the text input, into focus, and hits Backspace -- equivalent to the back button.
There go her 7 tedious minutes of form-filling -- this app isn't sophisticated enough to autosave a draft in real-time, after all.
Enter the onbeforeunload function.
I've borrowed from this guy a bit, but here's the code:
var confirm_exit = true;Originally, I'd planned to skip the ugly global variable and simply re-bind the onbeforeunload function, but apparently you can't rebind like that.
window.onbeforeunload = function() {
if( confirm_exit )
return "";
return; };
$(document).ready( function() {
$("#id_theform").submit( function() { confirm_exit = false; } );
} );
1 comment:
hOLy DAYUMz thta h3lped a l07 man thnx. ROCK ON FREVR!!!! COMP TECH 4 LYPH haha jkjk lol. nah just jokes. but really, man KUDOES!!!!!! A++ most def.
Post a Comment