Javascript: user confirmation when leaving single-page application
===

I would like to make the user confirm that she wants to leave my single-page application. ExtJS 4.1 provides the [`onWindowUnload`](http://docs.sencha.com/ext-js/4-1/#!/api/Ext.EventManager-method-onWindowUnload) in which I would like to plug in a [`Confirm` dialog](http://docs.sencha.com/ext-js/4-1/#!/api/Ext.window.MessageBox-method-confirm).

If the user decides to proceed closing the tab/window an [Ajax request](http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Ajax) to the logout URL should tell the server-side that the user has logged out.

Is the above approach possible?

Is it possible to plug the `onWindowUnload` event in ExtJS [`MVC controller`](http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller)?

**P.S.** *User leaving single-page app* can be any of the following: browser tab close, browser window close, browser back button, browser forward button.