2012-12-17 72 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