Reputation: 1214
In ExtJS 5 I'm getting console warning saying
[W] Ext.EventManager is deprecated. Use Ext.dom.Element#addListener to attach an event listener.
I am using code statement bellow,
Ext.EventManager.on(window, 'beforeunload', function() {
//code here
});
I understand that Ext.EventManager
is deprecated but how should I replace my code statement to work it in extjs 5 ?
Upvotes: 2
Views: 1794
Reputation: 3152
Just do:
Ext.getWin().[m]on('beforeunload', function() {
//code here
});
You could've find that yourself in the manual. Form the docs:
Registers event handlers on DOM elements.
This class is deprecated. Please use the Ext.dom.Element api to attach listeners to DOM Elements. For example:
var element = Ext.get('myId');
element.on('click', function(e) {
// event handling logic here
});
Upvotes: 0
Reputation: 14591
Use getWin()
method and append event handler using on
.
Ext.getWin().on('beforeunload',function(){
//code here
});
Other possible option would be to use pure JavaScript.
window.onbeforeunload = function(){
//Code here
};
Upvotes: 7