a flash movie where users can draw is calling a JS Function. Whenever something is changed in the movie calls listenToUnload(true). Whenever the save button in the Flashmovie is pressed listenToUnload(false); is called.
function listenToUnload(saved) {
if (saved) {
$(window).bind('unload', function() {
closeWindowWarning;
});
} else if (!saved) {
$(window).unbind('unload');
}
}
function closeWindowWarning() { return "You haven't saved your last changes"; }
So, I actually wonder if this is the correct way to do this?
Because listenToUnload(true) could be called multiple times in a row and I don’t want to have the unload function bound multiple times to the window.
Is this the correct way of doing this? Any other approaches?
thank you
First, you need to bind on
beforeunload, notunload.You can store the flag (whether to confirm before unload) in a variable, or in
$(document).data('confirm_unload', TRUE_OR_FALSE)and then:And of course bind the beforeunload event once:
You don’t need to wrap
closeWindowWarningin another function.