0
votes

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?

1

1 Answers

8
votes

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.