I managed to find a solution to this, although another job is required. For this solution, I assume that you are tracking when the view is dirty.
There are 4 main ways to exit a view;
- Click on the link to view
- "" " "
- "/"
1.
. , , . , , historyBack. :
historyBack: function() {
if (this.isDirty) {
answer = confirm("There are unsaved changes.\n\nDo you wish to continue?")
if (answer) {
this.isDirty = false
window.history.back()
}
}
else {
window.history.back()
}
}
2.
, execute, navigate, .
, , . , , .
:
_.extend(Backbone.Router.prototype, {
execute: function (callback, args, name) {
if (Backbone.Router.isDirty) {
answer = confirm "There are unsaved changes.\n\nDo you wish to continue?";
if (!answer) {
return false;
}
}
Backbone.Router.isDirty = false
if (callback) callback.apply(this, args)
}
}
3.
Javascript, , beforeunload (. ). , , , , :
onShow: function() {
$(window).bind("beforeunload", function (e) {
if (this.isDirty) {
return "There are unsaved changes.";
}
}
}
onDestroy: function() {
$(window).unbind("beforeunload");
}
4. /
, . / , 1 3, , , .
/ , : . , "" , , .
, , , .