0

I am working with ext js 4.1. I am developing an application that have to support IE9, the latest Firefox, the latest Chrome and Safari.

I need to show an alert message when the user wants to leave the if there are some data that is pending to submit.

I did the following using raw Javascript:

window.onbeforeunload=function(){
    if (Ext.getStore('LocalChangesStore')){
        if (Ext.getStore('LocalChangesStore').getCount() > 0) {
            return 'Your changes are be lost.'; 
        } 
    }
};

I am wondering if that would be possible with ext js. I saw the following function:

app.js:

EventManager.onWindowUnload( function(){
    if (Ext.getStore('LocalChangesStore')){
        if (Ext.getStore('LocalChangesStore').getCount() > 0) {
            return 'Your changes are be lost.'; 
        } 
    }        
    }, this
);

but it did not work.

Can somebody let me know which would be the best approach to solve this issue?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Federico Alvariz
  • 81
  • 1
  • 2
  • 4
  • 1
    See http://stackoverflow.com/questions/6047862/attach-extjs-mvc-controllers-to-dom-elements-not-components – AndreKR Dec 17 '12 at 05:21

1 Answers1

8

The onWindowUnload method attachs a function to the unload event but what you need is attach a function to the beforeunload event. Try this please

Ext.EventManager.on(window, 'beforeunload', function() {
    return 'Your changes are be lost.';
});

Good luck.

lontivero
  • 5,235
  • 5
  • 25
  • 42