Reputation: 2275
I have view and i want to fire one event when view unloaded.
Backbone.View.extend({
initializer : function() {
// Constructor
},
render : function() {
// My render logic.
}
})
Now how to fire one event when above view unloaded.
Upvotes: 1
Views: 1879
Reputation: 1316
I am not sure you can do that. You may want to find a workaround using
window.addEventListener('beforeunload', myFunction);
Upvotes: 1
Reputation: 14796
You can override the remove
method from Backbone.View as:
remove: function () {
this.trigger('view:unload'); //Whatever event name
Backbone.View.prototype.remove.call(this); //Important
},
It is important to call the original function to delete correctly the view.
Upvotes: 1