wood burning stoves 2.0*
The moose likes Servlets and the fly likes How do i trap the event of a browser window getting closed ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How do i trap the event of a browser window getting closed ?" Watch "How do i trap the event of a browser window getting closed ?" New topic
Author

How do i trap the event of a browser window getting closed ?

Rasmeet Devji
Greenhorn

Joined: Dec 08, 2000
Posts: 17
Hi guys!!
I need to know if it were possible to trap the event of a browser window getting closed, in java.
The reason why i want to do is this :
I've a chat application where in i have a logout button.
Now if the user clicks the logout button, i update his record back in the database and sign him off.
So far so good......
But the problem is, what if the user closes the browser window directly, i.e. without clicking on the logout button.
In any case i need to update his record, but how do i do this ???
Anyone to help me out ???
Thanks all !!
ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
I think you must be using applets in your chat application ,
you can make java script to commuicate with your applet , use
document.applet["appletname"].appletmethods , kind of stuff to execute method of the applet , and then in html body tag use
onunload event so it will notify javascript about unload and javascript will notify applet about it ,
hope this helps.
Rasmeet Devji
Greenhorn

Joined: Dec 08, 2000
Posts: 17
Hi Ray,
Thanks for the reply, but i'm afraid it did'nt help me much.
May be i'll explain it clearly. I have a servlet which embeds the html part (user interface).
When i tried calling the method of the applet, it didn't work out well
here's the sample code :
out.println("<html>");
out.println("<head><title>Mindteck Chat</title></head>");
out.println("<script language = 'javascript'>");
out.println("function logout()");
out.println("{");
out.println("var msg = \"leaves the room\" ");
out.println("document.chatapplet.broadcastMessage(msg)");
out.println("}");
out.println("</script>");
out.println("<body background=\"http://rasmeet:8080/gray.jpg\" onUnload = \"logout()\">");
out.println("<applet name = chatapplet code = "+ applet1 +
" codebase=/ " + "width = 600 height = 300>");
if(client != null)
{
out.println("<PARAM NAME = client VALUE=\" " + client + "\">");
}
out.println("</applet>");
out.println("</body>");
out.println("</html>");
what could be the reason ?
Thanx again !!
 
GeeCON Prague 2014
 
subject: How do i trap the event of a browser window getting closed ?