GWT 应用程序如何确定浏览器窗口或选项卡是否失去焦点,即变得不活动?我需要这个来将基于画布的应用程序切换到暂停状态,但仅当整个浏览器处于非活动状态时。如何才能做到这一点?欢迎任何想法。提前致谢。
Window onblur没有现成的实现,需要自己写
private native static void initialize() /*-{
$wnd.onblur = new function( e ) {
@packagepath.WindowEventManager::getInstance()().notifyOnBlur( e );
}
See this for full implementation.
这是对我有用的代码:
private native void listenForBlur(MyClass instance) /*-{
$wnd.addEventListener('blur', function() {
[email protected]::handleFocusLost()();
});
}-*/;
private void handleFocusLost() {
// do something
}
然后我调用函数如下:
listenForBlur(this);