0

我正在使用 ext js 4.1。我正在开发一个必须支持 IE9、最新的 Firefox、最新的 Chrome 和 Safari 的应用程序。

当用户想要离开时,如果有一些数据等待提交,我需要显示一条警报消息。

我使用原始 Javascript 执行了以下操作:

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

我想知道ext js是否可以做到这一点。我看到了以下功能:

应用程序.js:

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

但它没有用。

有人可以让我知道哪种方法是解决此问题的最佳方法吗?

4

1 回答 1

8

onWindowUnload方法将一个函数附加到 unload 事件,但您需要将一个函数附加到beforeunload事件。请试试这个

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

祝你好运。

于 2012-12-17T12:25:02.023 回答