View Full Version : [SOLVED] Confirm navigation?

9 Sep 2010, 1:29 PM

I have a large application that is based on ExtJS. It consists of a viewport and multiple panels and tabs within that viewport. I would like to pop up a message if changes have been made on the page should the user choose to navigate away from the page, e.g. presses the back button or refresh.

The user should be able to cancel the action or press ok to continue.

I have seen this functionality in web pages before now so I know it is possible, I just don't know where to look to put the code.

Can anyone point me in the right direction please?


9 Sep 2010, 1:46 PM
Ext.EventManager.on(window, 'beforeunload', function() {
alert('before unload');

Ext.EventManager.on(window, 'unload', function() {

14 Sep 2010, 11:21 AM
Thanks for pointing me in the right direction. I'm not sure why but your example didn't work, however the following code did the trick.

For anyone that reads this later, this is an unusual handler that requires a string to be returned in order to display the dialog box and a null to be returned to skip the dialog.

window.onbeforeunload = function() {

return "You have made changes, are you sure you would like to navigate away from the page?";
return null;