2012-12-17 71 views
0

我正在使用ext js 4.1。我正在开发一个应用程序,它必须支持IE9,最新的FF,最新的Chrome和Safari。ExtJS 4.1:卸载事件

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

我做了以下使用原始的Java脚本

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

我想知道如果这将是可能的Ext JS的。我看到了下面的函数

app.js:

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

,但没有奏效。

有人可以告诉我哪个是解决此问题的最佳方法。

由于提前, 费德里科

+1

看到http://stackoverflow.com/questions/6047862/attach-extjs-mvc-controllers-to-dom-elements-not-components – AndreKR

回答

7

onWindowUnload方法attachs一个函数来卸载事件,但你需要的是附加功能的beforeunload事件。试试这个请

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

祝你好运。

+0

它的工作,谢谢! –

+5

如果有效,你为什么不接受答案? – lontivero

+0

Dous不再适用于Chrome!事件自7.19.2016起被忽略 – Sangoku