Handling browser close event (onunload?)

740 views
Skip to first unread message

Md Mozammel Haque

unread,
Dec 19, 2006, 1:16:34 AM12/19/06
to Google-We...@googlegroups.com
Hi,

I have integrated a GWT application (uses RPC) with my existing Spring MVC web application. My GWT application fires within a pop-up when a user clicks on a certain link in my core application page. The popup is mainly used for online chat purpose and is currently working fine. When the user is done chatting, he can press a close button to end the chat session.

Now I need to do some cleanup code when user presses the close button within my GWT page. The problem is when user presses the popup's close button (browser close button), I still didn't handle that event.

How can I catch that event from GWT so that I can call a certain method and perform similar clean-up procedure? Any help will be much appreciated.

Thanking you,
Mozammel

Md Mozammel Haque

unread,
Dec 19, 2006, 1:59:01 AM12/19/06
to Google-We...@googlegroups.com
I've implemented a JSNI method which calls my GWT method endConneciton. But when I close the popup window, the endConnection() GWT method is not being called. Am I doing anything wrong here?

  public native void closeChatDelegator() /*-{
    $win.body.onunload = function() {
      this.@com.domain.project.client.ChatWidget::endConnection()();
    }
  }-*/;


- Mozammel

dominik_steiner

unread,
Dec 19, 2006, 2:17:38 AM12/19/06
to Google Web Toolkit
Hi there,

did you try to use $wnd.body.onload?

I think that you should use $wnd instead of $win

Dominik

Md Mozammel Haque

unread,
Dec 19, 2006, 4:17:40 AM12/19/06
to Google-We...@googlegroups.com
Hi Dominik:

I tried $wnd.body.onunload, but it is not working. By the way, as you specified, I also tried $wnd.body.onload, which didn't work also. I'm trying to execute a GWT method on window close event, so I think $wnd.body.unload is the correct one. But eventhough, my implementation is not working.

Any idea?

- Mozammel

Md Mozammel Haque

unread,
Dec 19, 2006, 5:28:49 AM12/19/06
to Google-We...@googlegroups.com
Answering my own question:

I've found the solution. It is actually pretty simple, sorry that I've overlooked it first time. I just implemented WindowCloseListener on my widget and then added Window.addWindowCloseListener (this) on the same widget and implemented the interface method appropriately. This solved my problem.

- Mozammel


On 12/19/06, Md Mozammel Haque <moza...@gmail.com> wrote:

dominik_steiner

unread,
Dec 20, 2006, 2:08:12 AM12/20/06
to Google Web Toolkit
Hi Mozammel,

sorry for my previous posting, what I wanted to write was
$wnd.body.unload and to point to wnd instead of win. But good news to
hear that you were able to solve your problem.

Dominik

Reply all
Reply to author
Forward
0 new messages