Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Browser Close Event? Onunload?

    Hi there,

    I am using SmartGWT 3.0 and I wonder if there is a possibility to do something before a User closes the Browser Window. (Something like onUnload in JS)

    This must not be a 100% solution. I have to invalidate a host-session. My fallback solution is to use a HttpSessionListener to do this, but it would be nice to do this immediately after a User closes the Browser window.

    Thank you!

    #2
    You could do this:
    1. Periodically send a KeepAlive message to the server (say every 5 minutes) so that the server knows that the Browser is up
    2. Server-side job that marks the browser session as completed, if no KeepAlive message was received within 6 minutes
    3. The following code to catch the browser closing (will not catch browser GPF'ing or connections dying), to handle the majority case:
    Code:
    import com.google.gwt.event.logical.shared.CloseHandler;
    import com.google.gwt.event.logical.shared.CloseEvent;
    
    final CloseHandler closeHandler = new CloseHandler () {
      public void onClose (final CloseEvent closeEvent) {
        // tell the server i am going away
      }
    };
    com.google.gwt.user.client.Window.addCloseHandler (closeHandler);
    4. The HttpSessionListener catch-all (though this should not be needed because of #2). Plus it might not kick in until the session expires, which could be a very long time...

    Or just do #3

    Comment


      #3
      Code:
      final CloseHandler closeHandler = new CloseHandler () {
        public void onClose (final CloseEvent closeEvent) {
          // tell the server i am going away
        }
      };
      com.google.gwt.user.client.Window.addCloseHandler (closeHandler);
      That's it! Thank you very much....

      Comment

      Working...
      X