Abhijit Muke
Abhijit Muke

Reputation: 1214

Ext.EventManager is deprecated in ExtJS 5

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

Answers (2)

Tarabass
Tarabass

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

Gilsha
Gilsha

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

Related Questions