View Full Version : How do I handle an event on a javascript object (window)
el_chief
25 Apr 2012, 5:32 PM
I want to handle an event on a POJO (plain old javascript object), the global window object
I could use window.attachEvent or window.addEventListener, but what is the Ext way?
In particular, I'd like to handle the window.onbeforeunload event, but would like a generic method.
window.onbeforeunload is not acceptable :)
Thanks
vietits
25 Apr 2012, 6:12 PM
It seems that you want to add listener to DOM object by using Ext. If so, here is my suggestion:
var object = Ext.get(domObject);
object.on({...});
scottmartin
25 Apr 2012, 6:12 PM
Misunderstood question .. removed answer
Scott.
el_chief
25 Apr 2012, 6:36 PM
looks like Ext.get(window) returns null...
vietits
25 Apr 2012, 7:37 PM
With Ext 4.1, you can use Ext.get(). However, you could try the following solution:
var object = new Ext.Element(domObject);
object.on(....);
khmurach
26 Apr 2012, 7:10 AM
Demo here http://ext4all.com/post/how-to-handle-an-event-of-javascript-window
el_chief
26 Apr 2012, 11:01 AM
Demo here http://ext4all.com/post/how-to-handle-an-event-of-javascript-window
this looks like the best generic method. doesn't work with onbeforeunload, but that's probably a bug :)
thanks!
khmurach
26 Apr 2012, 11:14 AM
Use
Ext.EventManager.addListener(window, 'beforeunload', function (e) {
return alert('beforeunload');
});
Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.