Does anybody know how to handle window onfocus/onblur events? I tried:
$wnd.onfocus = function() {
alert("Test");
};
in native method, but it doesn't work in IE. In Opera and FF it works
fine.
Thanks.
Thanks,
Eric
I tried DOM.addEventPreview to catch these events, but onblur event
doesn't fire correctly when window lost focus. :(
public class WindowEventManager {
private static final WindowEventManager instance = new
WindowEventManager();
protected List listeners;
private WindowEventManager() {
WindowEventManager.initialize();
this.listeners = new ArrayList();
}
private native static void initialize() /*-{
$wnd.onblur = new function( e ) {
@packagepath.WindowEventManager::getInstance()().notifyOnBlur( e );
}
$wnd.onfocus = new function( e ) {
@packagepath.WindowEventManager::getInstance()().notifyOnFocus( e );
}
}-*/;
public static void getInstance() {
return WindowEventManager.instance;
}
private void notifyOnFocus( Event e ) {
for ( Iterator i = this.listeners.iterator(); i.hasNext(); ) {
((WindowEventListener) i.next()).onFocus( e );
}
}
private void notifyOnBlur( Event e ) {
// duplicate notifyOnFocus, but call the onBlur method
}
public void addListener( WindowEventListener wel ) {
this.listeners.add( wel );
}
public void removeListener( WindowEventListener wel ) {
this.listeners.remove( wel );
}
}
public interface WindowFocusListener() {
public void onFocus( Event e );
public void onBlur( Event e );
}
Thanks,
Eric
The problem comes when you need a doctype for one thing to work, but
need to remove it for another to work. :) I haven't figured out how
to manage that.
Thanks,
Eric
I don't have doctype. But I noticed if Window.onblur = ... located in
gwt.js events fire in IE also.
Thanks,
Eric
Sorry for my poor English.