Reputation: 12512
I have a function that checks for a particular event and when it detects it is displays an overlay message. Until that happens I need to have beforeunload in place to warn a user about potential data loss in case a they decide to leave the page before the task is complete. I added it in the following manner, but even when the task is complete and the beforeunload should not fire it still gets triggered. I think it is due to the bind. Is there another way it can be implemented to achieve what i am trying to accomplish?
if (!$("#area").find('.item').length) {
$("#message").dialog({
modal: true
});
} else {
$(window).bind("beforeunload", function() {
return "Are you really sure?";
});
}
Upvotes: 1
Views: 38