user1152442
user1152442

Reputation: 75

GWT Window onBlur

how can a GWT app determine if the browser window or tab loses focus i.e. gets inactive? I need this to switch a canvas based application into pause state, but only when the whole browser gets inactive. How can this be done? Any ideas are welcome. Thanks in advance.

Upvotes: 2

Views: 1385

Answers (2)

Mark
Mark

Reputation: 4935

Here is the code that worked for me:

    private native void listenForBlur(MyClass instance) /*-{
        $wnd.addEventListener('blur', function() {
            [email protected]::handleFocusLost()();
        });

    }-*/;


    private void handleFocusLost() {
       // do something
    }

I then call the function as follows:

listenForBlur(this);

Upvotes: 1

Suresh Atta
Suresh Atta

Reputation: 122008

There is no such ready implementation for Window onblur.You have to write on your own

private native static void initialize() /*-{
$wnd.onblur = new function( e ) {
@packagepath.WindowEventManager::getInstance()().notifyOnBlur( e );
}

See this for full implementation.

Upvotes: 4

Related Questions