algiogia
algiogia

Reputation: 955

GWT: redirect user on window close

I need to intercept when the user navigates away from the page, to redirect him somewhere else.

This will be used to manage a sales flow to avoid going back.

We tried something like

Window.addCloseHandler(new CloseHandler<Window>() {

  @Override
  public void onClose(CloseEvent<Window> event) {

    ...
    Window.open("main");

  }
});

but this only works on Firefox. On Chrome the code is executed but there is no redirection. If I change to "_blank" then a new window opens with the given URL but this is not the required behaviour.

Upvotes: 0

Views: 119

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

I think this behavior is per-spec (HTML5):

If there is a preexisting attempt to navigate the browsing context, and the source browsing context is the same as the browsing context being navigated, and that attempt is currently running the unload a document algorithm, and the origin of the URL of the resource being loaded in that navigation is not the same origin as the origin of the URL of the resource being loaded in this navigation, then abort these steps without affecting the preexisting attempt to navigate the browsing context.

Source: http://www.w3.org/TR/html5/browsers.html#navigate

Upvotes: 1

Related Questions